gh-119180: Add evaluate functions for type params and type aliases (#122212)

This commit is contained in:
Jelle Zijlstra 2024-07-27 10:24:10 -07:00 committed by GitHub
parent cbac8a3888
commit ae192262ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 385 additions and 159 deletions

View file

@ -773,6 +773,25 @@ class TestGetAnnotations(unittest.TestCase):
)
class TestCallEvaluateFunction(unittest.TestCase):
def test_evaluation(self):
def evaluate(format, exc=NotImplementedError):
if format != 1:
raise exc
return undefined
with self.assertRaises(NameError):
annotationlib.call_evaluate_function(evaluate, annotationlib.Format.VALUE)
self.assertEqual(
annotationlib.call_evaluate_function(evaluate, annotationlib.Format.FORWARDREF),
annotationlib.ForwardRef("undefined"),
)
self.assertEqual(
annotationlib.call_evaluate_function(evaluate, annotationlib.Format.SOURCE),
"undefined",
)
class MetaclassTests(unittest.TestCase):
def test_annotated_meta(self):
class Meta(type):