summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_dataclasses.py
diff options
context:
space:
mode:
authorCarl Meyer <carl@oddbird.net>2023-01-06 00:19:40 (GMT)
committerGitHub <noreply@github.com>2023-01-06 00:19:40 (GMT)
commit0a7936a38f0bab1619ee9fe257880a51c9d839d5 (patch)
treed80b3a2e48200408d41b415beacd59a1f4b2b0c5 /Lib/test/test_dataclasses.py
parentcc8748712e78805c5be4a0a3f98cfb5c35026d0e (diff)
downloadcpython-0a7936a38f0bab1619ee9fe257880a51c9d839d5.zip
cpython-0a7936a38f0bab1619ee9fe257880a51c9d839d5.tar.gz
cpython-0a7936a38f0bab1619ee9fe257880a51c9d839d5.tar.bz2
gh-90104: avoid RecursionError on recursive dataclass field repr (gh-100756)
Avoid RecursionError on recursive dataclass field repr
Diffstat (limited to 'Lib/test/test_dataclasses.py')
-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 a09f36c..81a36aa 100644
--- a/Lib/test/test_dataclasses.py
+++ b/Lib/test/test_dataclasses.py
@@ -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_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