Skip to content

Commit d92c59f

Browse files
authored
bpo-43764: Fix __match_args__ generation logic for dataclasses (GH-25284)
1 parent 28d28e0 commit d92c59f

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

Lib/dataclasses.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ def _process_class(cls, init, repr, eq, order, unsafe_hash, frozen):
10171017
str(inspect.signature(cls)).replace(' -> NoneType', ''))
10181018

10191019
if '__match_args__' not in cls.__dict__:
1020-
cls.__match_args__ = tuple(f.name for f in flds if f.init)
1020+
cls.__match_args__ = tuple(f.name for f in field_list if f.init)
10211021

10221022
abc.update_abstractmethods(cls)
10231023

Lib/test/test_dataclasses.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3432,6 +3432,14 @@ class C:
34323432
__match_args__ = ma
34333433
self.assertIs(C(42).__match_args__, ma)
34343434

3435+
def test_bpo_43764(self):
3436+
@dataclass(repr=False, eq=False, init=False)
3437+
class X:
3438+
a: int
3439+
b: int
3440+
c: int
3441+
self.assertEqual(X.__match_args__, ("a", "b", "c"))
3442+
34353443

34363444
if __name__ == '__main__':
34373445
unittest.main()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix an issue where :data:`~object.__match_args__` generation could fail for
2+
some :mod:`dataclasses`.

0 commit comments

Comments
 (0)