gh-90104: avoid RecursionError on recursive dataclass field repr (gh-100756)

Avoid RecursionError on recursive dataclass field repr
This commit is contained in:
Carl Meyer 2023-01-05 17:19:40 -07:00 committed by GitHub
parent cc8748712e
commit 0a7936a38f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 21 deletions

View file

@ -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