mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
bpo-43764: Fix __match_args__
generation logic for dataclasses (GH-25284)
This commit is contained in:
parent
28d28e053d
commit
d92c59f486
3 changed files with 11 additions and 1 deletions
|
@ -1017,7 +1017,7 @@ def _process_class(cls, init, repr, eq, order, unsafe_hash, frozen):
|
||||||
str(inspect.signature(cls)).replace(' -> NoneType', ''))
|
str(inspect.signature(cls)).replace(' -> NoneType', ''))
|
||||||
|
|
||||||
if '__match_args__' not in cls.__dict__:
|
if '__match_args__' not in cls.__dict__:
|
||||||
cls.__match_args__ = tuple(f.name for f in flds if f.init)
|
cls.__match_args__ = tuple(f.name for f in field_list if f.init)
|
||||||
|
|
||||||
abc.update_abstractmethods(cls)
|
abc.update_abstractmethods(cls)
|
||||||
|
|
||||||
|
|
|
@ -3432,6 +3432,14 @@ class TestMatchArgs(unittest.TestCase):
|
||||||
__match_args__ = ma
|
__match_args__ = ma
|
||||||
self.assertIs(C(42).__match_args__, ma)
|
self.assertIs(C(42).__match_args__, ma)
|
||||||
|
|
||||||
|
def test_bpo_43764(self):
|
||||||
|
@dataclass(repr=False, eq=False, init=False)
|
||||||
|
class X:
|
||||||
|
a: int
|
||||||
|
b: int
|
||||||
|
c: int
|
||||||
|
self.assertEqual(X.__match_args__, ("a", "b", "c"))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix an issue where :data:`~object.__match_args__` generation could fail for
|
||||||
|
some :mod:`dataclasses`.
|
Loading…
Add table
Add a link
Reference in a new issue