[issue43764] Turning off generation of __match_args__ for dataclasses

Brandt Bucher report at bugs.python.org
Wed Apr 7 13:41:48 EDT 2021


Brandt Bucher <brandtbucher at gmail.com> added the comment:

I agree with Eric. You can already disable the automatic creation of __match_args__ by setting it yourself on the class being decorated, and "__match_args__ = ()" will make the class behave the exact same as if __match_args__ is not defined at all.

>>> from dataclasses import dataclass
>>> @dataclass 
... class X:
...     __match_args__ = ()
...     a: int
...     b: int
...     c: int
... 
>>> X.__match_args__
()

I too have trouble imagining a case where the actual *presence* of the attribute matters. But assuming those cases exist, wouldn't a simple "del X.__match_args__" suffice?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43764>
_______________________________________


More information about the Python-bugs-list mailing list