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

dataclasses are not cooperative #142

Closed
a-recknagel opened this issue Feb 12, 2019 · 2 comments
Closed

dataclasses are not cooperative #142

a-recknagel opened this issue Feb 12, 2019 · 2 comments

Comments

@a-recknagel
Copy link

a-recknagel commented Feb 12, 2019

dataclasses are not cooperative:

>>> class SayFoo:
...     def __init__(self, *args, **kwargs):
...         print('Foo')
...         super().__init__(*args, **kwargs)
... 
>>> @dataclass
... class DC(SayFoo):
...     var: int
...     
>>> DC(1)
DC(var=1)  # doesn't say 'Foo'

This makes writing useful mixins for dataclasses quite hard. Is there a reason why they were written this way?

@ericvsmith
Copy link
Owner

Because I don't know the signature of the base class's __init__. You may call it yourself in __post_init__.

I'm closing this because this repo is only for the backport of dataclasses to Python 3.6. If you want to discuss this further, I recommend using the python-dev mailing list, or bugs.python.org.

@a-recknagel
Copy link
Author

Thanks for the answer, sorry for using the wrong channel.

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

2 participants