summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorCarl Meyer <carl@oddbird.net>2023-01-06 02:15:27 (GMT)
committerGitHub <noreply@github.com>2023-01-06 02:15:27 (GMT)
commitebe8d2340733a36fd7555e1c75bb103d9ef465ec (patch)
treec5ef7d62c8c3da2626ee050468c0c977810acb6d /Lib/test
parentf5fa2c1e7f158fbc2ac4ad936e39fbe6253ae354 (diff)
downloadcpython-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.py18
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: