Skip to content

Commit fc00d21

Browse files
committed
Add test for re-evaluating ForwardRef generics
1 parent 8708272 commit fc00d21

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

Lib/test/test_annotationlib.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,6 +1926,26 @@ def test_fwdref_invalid_syntax(self):
19261926
with self.assertRaises(SyntaxError):
19271927
fr.evaluate()
19281928

1929+
def test_re_evaluate_generics(self):
1930+
global global_alias
1931+
1932+
# If we've already run this test before,
1933+
# ensure the variable is still undefined
1934+
if "global_alias" in globals():
1935+
del global_alias
1936+
1937+
class C:
1938+
x: global_alias[int]
1939+
1940+
# Evaluate the ForwardRef once
1941+
evaluated = get_annotations(C, format=Format.FORWARDREF)["x"].evaluate(
1942+
format=Format.FORWARDREF
1943+
)
1944+
1945+
# Now define the global and ensure that the ForwardRef evaluates
1946+
global_alias = list
1947+
self.assertEqual(evaluated.evaluate(), list[int])
1948+
19291949

19301950
class TestAnnotationLib(unittest.TestCase):
19311951
def test__all__(self):

0 commit comments

Comments
 (0)