Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patch / patch_to doesn't work with inheritance #535

Open
dsm-72 opened this issue Aug 18, 2023 · 0 comments
Open

patch / patch_to doesn't work with inheritance #535

dsm-72 opened this issue Aug 18, 2023 · 0 comments

Comments

@dsm-72
Copy link
Contributor

dsm-72 commented Aug 18, 2023

See example below

cell 1

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

@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

list(c.get_class_keywords() for c in (Foo, Qux, Bar, Baz))
> [[], [], [], []]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant