mirror of
https://github.com/python/cpython.git
synced 2025-07-19 09:15:34 +00:00
[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:
parent
d6b8413e94
commit
f488831576
3 changed files with 40 additions and 21 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue