mirror of
https://github.com/python/cpython.git
synced 2025-11-01 14:11:41 +00:00
gh-90104: avoid RecursionError on recursive dataclass field repr (gh-100756)
Avoid RecursionError on recursive dataclass field repr
This commit is contained in:
parent
cc8748712e
commit
0a7936a38f
3 changed files with 40 additions and 21 deletions
|
|
@ -68,6 +68,24 @@ def test_field_repr(self):
|
|||
|
||||
self.assertEqual(repr_output, expected_output)
|
||||
|
||||
def test_field_recursive_repr(self):
|
||||
rec_field = field()
|
||||
rec_field.type = rec_field
|
||||
rec_field.name = "id"
|
||||
repr_output = repr(rec_field)
|
||||
|
||||
self.assertIn(",type=...,", repr_output)
|
||||
|
||||
def test_recursive_annotation(self):
|
||||
class C:
|
||||
pass
|
||||
|
||||
@dataclass
|
||||
class D:
|
||||
C: C = field()
|
||||
|
||||
self.assertIn(",type=...,", repr(D.__dataclass_fields__["C"]))
|
||||
|
||||
def test_dataclass_params_repr(self):
|
||||
# Even though this is testing an internal implementation detail,
|
||||
# it's testing a feature we want to make sure is correctly implemented
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue