[3.11] gh-90104: avoid RecursionError on recursive dataclass field repr (gh-100756) (GH-100784)

Avoid RecursionError on recursive dataclass field repr

(cherry picked from commit 0a7936a38f)

Automerge-Triggered-By: GH:ericvsmith
This commit is contained in:
Carl Meyer 2023-01-05 19:08:33 -07:00 committed by GitHub
parent d6b8413e94
commit f488831576
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 @@ class TestCase(unittest.TestCase):
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_named_init_params(self):
@dataclass
class C: