diff options
author | Jelle Zijlstra <jelle.zijlstra@gmail.com> | 2024-09-25 23:30:17 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-25 23:30:17 (GMT) |
commit | 0268b072d84bc4be890d1b7459815ba1cb9f9945 (patch) | |
tree | 4fccd592e2ce82ed2dbac8932782f9444ccecb54 /Lib | |
parent | ffdc80e93d9d947531fa0123e5b392c6f1fd9136 (diff) | |
download | cpython-0268b072d84bc4be890d1b7459815ba1cb9f9945.zip cpython-0268b072d84bc4be890d1b7459815ba1cb9f9945.tar.gz cpython-0268b072d84bc4be890d1b7459815ba1cb9f9945.tar.bz2 |
gh-119180: Disallow instantiation of ConstEvaluator objects (#124561)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_type_params.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_type_params.py b/Lib/test/test_type_params.py index dc0c0d0..8c21553 100644 --- a/Lib/test/test_type_params.py +++ b/Lib/test/test_type_params.py @@ -1452,3 +1452,14 @@ class TestEvaluateFunctions(unittest.TestCase): self.assertEqual(annotationlib.call_evaluate_function(case.evaluate_constraints, annotationlib.Format.VALUE), (int, str)) self.assertEqual(annotationlib.call_evaluate_function(case.evaluate_constraints, annotationlib.Format.FORWARDREF), (int, str)) self.assertEqual(annotationlib.call_evaluate_function(case.evaluate_constraints, annotationlib.Format.SOURCE), '(int, str)') + + def test_const_evaluator(self): + T = TypeVar("T", bound=int) + self.assertEqual(repr(T.evaluate_bound), "<constevaluator <class 'int'>>") + + ConstEvaluator = type(T.evaluate_bound) + + with self.assertRaisesRegex(TypeError, r"cannot create '_typing\._ConstEvaluator' instances"): + ConstEvaluator() # This used to segfault. + with self.assertRaisesRegex(TypeError, r"cannot set 'attribute' attribute of immutable type '_typing\._ConstEvaluator'"): + ConstEvaluator.attribute = 1 |