Brandt Bucher <[email protected]> added the comment:
> init=False is used to make sure there's no __init__ defined, because there's
> a difference between a class with an __init__ and one without. If there was a
> difference between __match_args__ being not present and __match_args__=(),
> then I'd support a matchargs=False argument.
Ah, I see now how this might possibly be useful.
If you want to inherit a parent's __match_args__ in a dataclass, it currently
must be as spelled something like:
@dataclass
class Child(Parent):
__match_args__ = Parent.__match_args__
...
It's even uglier when you're unsure if Parent defines __match_args__ at all, or
if multiple-inheritance is involved:
@dataclass
class Child(Parent, Mixin):
__match_args__ = ()
...
del Child.__match_args__
I'm not sure how likely it is that code out in the wild may need to look like
this. As I understand it, though, the fact that dataclasses allow for "normal"
inheritance is one of their big selling-points. So it could be a valid reason
to include this option.
If it seems like the above code might become reasonably common, I agree that
the proposed solution is much cleaner:
@dataclass(match_args=False)
class Child(Parent):
...
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue43764>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com