| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -320,15 +320,25 @@ class _DataclassParams: | |||
| 320 | 320 | 'order', | |
| 321 | 321 | 'unsafe_hash', | |
| 322 | 322 | 'frozen', | |
| 323 | + 'match_args', | ||
| 324 | + 'kw_only', | ||
| 325 | + 'slots', | ||
| 326 | + 'weakref_slot', | ||
| 323 | 327 | ) | |
| 324 | 328 | ||
| 325 | - def __init__(self, init, repr, eq, order, unsafe_hash, frozen): | ||
| 329 | + def __init__(self, | ||
| 330 | + init, repr, eq, order, unsafe_hash, frozen, | ||
| 331 | + match_args, kw_only, slots, weakref_slot): | ||
| 326 | 332 | self.init = init | |
| 327 | 333 | self.repr = repr | |
| 328 | 334 | self.eq = eq | |
| 329 | 335 | self.order = order | |
| 330 | 336 | self.unsafe_hash = unsafe_hash | |
| 331 | 337 | self.frozen = frozen | |
| 338 | + self.match_args = match_args | ||
| 339 | + self.kw_only = kw_only | ||
| 340 | + self.slots = slots | ||
| 341 | + self.weakref_slot = weakref_slot | ||
| 332 | 342 | ||
| 333 | 343 | def __repr__(self): | |
| 334 | 344 | return ('_DataclassParams(' | |
@@ -337,7 +347,11 @@ def __repr__(self): | |||
| 337 | 347 | f'eq={self.eq!r},' | |
| 338 | 348 | f'order={self.order!r},' | |
| 339 | 349 | f'unsafe_hash={self.unsafe_hash!r},' | |
| 340 | - f'frozen={self.frozen!r}' | ||
| 350 | + f'frozen={self.frozen!r},' | ||
| 351 | + f'match_args={self.match_args!r},' | ||
| 352 | + f'kw_only={self.kw_only!r},' | ||
| 353 | + f'slots={self.slots!r},' | ||
| 354 | + f'weakref_slot={self.weakref_slot!r}' | ||
| 341 | 355 | ')') | |
| 342 | 356 | ||
| 343 | 357 | ||
@@ -905,7 +919,9 @@ def _process_class(cls, init, repr, eq, order, unsafe_hash, frozen, | |||
| 905 | 919 | globals = {} | |
| 906 | 920 | ||
| 907 | 921 | setattr(cls, _PARAMS, _DataclassParams(init, repr, eq, order, | |
| 908 | - unsafe_hash, frozen)) | ||
| 922 | + unsafe_hash, frozen, | ||
| 923 | + match_args, kw_only, | ||
| 924 | + slots, weakref_slot)) | ||
| 909 | 925 | ||
| 910 | 926 | # Find our base classes in reverse MRO order, and exclude | |
| 911 | 927 | # ourselves. In reversed order so that more derived classes | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -68,6 +68,32 @@ def test_field_repr(self): | |||
| 68 | 68 | ||
| 69 | 69 | self.assertEqual(repr_output, expected_output) | |
| 70 | 70 | ||
| 71 | + def test_dataclass_params_repr(self): | ||
| 72 | + # Even though this is testing an internal implementation detail, | ||
| 73 | + # it's testing a feature we want to make sure is correctly implemented | ||
| 74 | + # for the sake of dataclasses itself | ||
| 75 | + @dataclass(slots=True, frozen=True) | ||
| 76 | + class Some: pass | ||
| 77 | + | ||
| 78 | + repr_output = repr(Some.__dataclass_params__) | ||
| 79 | + expected_output = "_DataclassParams(init=True,repr=True," \ | ||
| 80 | + "eq=True,order=False,unsafe_hash=False,frozen=True," \ | ||
| 81 | + "match_args=True,kw_only=False," \ | ||
| 82 | + "slots=True,weakref_slot=False)" | ||
| 83 | + self.assertEqual(repr_output, expected_output) | ||
| 84 | + | ||
| 85 | + def test_dataclass_params_signature(self): | ||
| 86 | + # Even though this is testing an internal implementation detail, | ||
| 87 | + # it's testing a feature we want to make sure is correctly implemented | ||
| 88 | + # for the sake of dataclasses itself | ||
| 89 | + @dataclass | ||
| 90 | + class Some: pass | ||
| 91 | + | ||
| 92 | + for param in inspect.signature(dataclass).parameters: | ||
| 93 | + if param == 'cls': | ||
| 94 | + continue | ||
| 95 | + self.assertTrue(hasattr(Some.__dataclass_params__, param), msg=param) | ||
| 96 | + | ||
| 71 | 97 | def test_named_init_params(self): | |
| 72 | 98 | @dataclass | |
| 73 | 99 | class C: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Add ``match_args``, ``kw_only``, ``slots``, and ``weakref_slot`` to | ||
| 2 | + ``_DataclassParams``. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments