[issue43764] Turning off generation of __match_args__ for dataclasses
Brandt Bucher
report at bugs.python.org
Wed Apr 7 13:48:56 EDT 2021
Brandt Bucher <brandtbucher at gmail.com> added the comment:
> Note that setting compare=False on a dataclass.field already excludes that field from __match_args__...
It appears you did find a genuine bug though! I was surprised by this comment, and after digging a bit deeper into _process_class found that we should be generating these from "field_list", not "flds":
>>> @dataclass(repr=False, eq=False, init=False)
... class X:
... a: int
... b: int
... c: int
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/home/bucher/src/cpython/Lib/dataclasses.py", line 1042, in wrap
return _process_class(cls, init, repr, eq, order, unsafe_hash, frozen)
File "/home/bucher/src/cpython/Lib/dataclasses.py", line 1020, in _process_class
cls.__match_args__ = tuple(f.name for f in flds if f.init)
UnboundLocalError: local variable 'flds' referenced before assignment
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43764>
_______________________________________
More information about the Python-bugs-list
mailing list