AnswerDotAI / AnswerDotAI/fastcore
patch / patch_to doesn't work with inheritance
- Dominant language
- Jupyter Notebook
- Stars
- 1.1k
- Forks
- 295
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 7
Description
See example below
#### cell 1
```python
from fastcore.basics import patch, patch_to
class KeywordArgumentsMixin:
...
# NOTE: this works if uncommented
# @classmethod
# def get_class_keywords(cls:KeywordArgumentsMixin) -> list:
# return inspect.getfullargspec(cls.__init__).kwonlyargs
```
#### cell 2
```python
@dataclass
class Foo(KeywordArgumentsMixin):
_: KW_ONLY
a: int = 1
b: int = 2
c: int = 3
@dataclass
class Qux(KeywordArgumentsMixin):
_: KW_ONLY
q: str = -2
u: str = -1
x: int = 0
#| export
@dataclass
class Bar(Foo):
_: KW_ONLY
x: int = 7
y: int = 8
z: int = 9
@dataclass
class Baz(Bar, Qux):
_: KW_ONLY
a: int = 6
b: int = 7
q: int = 0
```
#### cell 3
```
@patch(cls_method=True)
def get_class_keywords(cls:KeywordArgumentsMixin) -> list:
return inspect.getfullargspec(cls.__init__).kwonlyargs
```
#### cell 4
```python
list(c.get_class_keywords() for c in (Foo, Qux, Bar, Baz))
> [[], [], [], []]
```
Contributor guide
Research direction
Start with the patch and patch_to entry points used in cell 3, then run the four-cell example to inspect how the inherited KeywordArgumentsMixin method is attached. Done means the example's get_class_keywords calls work for Foo, Qux, Bar, and Baz without uncommenting the mixin method.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100