diff options
author | Carl Meyer <carl@oddbird.net> | 2023-01-06 02:15:27 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-06 02:15:27 (GMT) |
commit | ebe8d2340733a36fd7555e1c75bb103d9ef465ec (patch) | |
tree | c5ef7d62c8c3da2626ee050468c0c977810acb6d /Lib/test | |
parent | f5fa2c1e7f158fbc2ac4ad936e39fbe6253ae354 (diff) | |
download | cpython-ebe8d2340733a36fd7555e1c75bb103d9ef465ec.zip cpython-ebe8d2340733a36fd7555e1c75bb103d9ef465ec.tar.gz cpython-ebe8d2340733a36fd7555e1c75bb103d9ef465ec.tar.bz2 |
[3.10] gh-90104: avoid RecursionError on recursive dataclass field repr (gh-100756) (GH-100785)
Avoid RecursionError on recursive dataclass field repr
(cherry picked from commit 0a7936a38f0bab1619ee9fe257880a51c9d839d5)
Automerge-Triggered-By: GH:ericvsmith
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_dataclasses.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_dataclasses.py b/Lib/test/test_dataclasses.py index e805f0c..a642ed9 100644 --- a/Lib/test/test_dataclasses.py +++ b/Lib/test/test_dataclasses.py @@ -67,6 +67,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: |