@@ -73,6 +73,30 @@ def inner(arg: x):
7373anno = get_annotations (inner ,format = Format .FORWARDREF )
7474self .assertEqual (anno ["arg" ],x )
7575
76+ def test_multiple_closure (self ):
77+ def inner (arg :x [y ]):
78+ pass
79+
80+ fwdref = get_annotations (inner ,format = Format .FORWARDREF )["arg" ]
81+ self .assertIsInstance (fwdref ,ForwardRef )
82+ self .assertEqual (fwdref .__forward_arg__ ,"x[y]" )
83+ with self .assertRaises (NameError ):
84+ fwdref .evaluate ()
85+
86+ y = str
87+ fwdref = get_annotations (inner ,format = Format .FORWARDREF )["arg" ]
88+ self .assertIsInstance (fwdref ,ForwardRef )
89+ extra_name ,extra_val = next (iter (fwdref .__extra_names__ .items ()))
90+ self .assertEqual (fwdref .__forward_arg__ .replace (extra_name ,extra_val .__name__ ),"x[str]" )
91+ with self .assertRaises (NameError ):
92+ fwdref .evaluate ()
93+
94+ x = list
95+ self .assertEqual (fwdref .evaluate (),x [y ])
96+
97+ fwdref = get_annotations (inner ,format = Format .FORWARDREF )["arg" ]
98+ self .assertEqual (fwdref ,x [y ])
99+
76100def test_function (self ):
77101def f (x :int ,y :doesntexist ):
78102pass
@@ -1688,6 +1712,14 @@ def test_forward_repr(self):
16881712repr (List [ForwardRef ("int" ,module = "mod" )]),
16891713"typing.List[ForwardRef('int', module='mod')]" ,
16901714 )
1715+ self .assertEqual (
1716+ repr (List [ForwardRef ("int" ,module = "mod" ,is_class = True )]),
1717+ "typing.List[ForwardRef('int', module='mod', is_class=True)]" ,
1718+ )
1719+ self .assertEqual (
1720+ repr (List [ForwardRef ("int" ,owner = "class" )]),
1721+ "typing.List[ForwardRef('int', owner='class')]" ,
1722+ )
16911723
16921724def test_forward_recursion_actually (self ):
16931725def namespace1 ():
@@ -1793,6 +1825,19 @@ def test_evaluate_forwardref_format(self):
17931825support .EqualToForwardRef ('"a" + 1' ),
17941826 )
17951827
1828+ def test_evaluate_notimplemented_format (self ):
1829+ class C :
1830+ x :alias
1831+
1832+ fwdref = get_annotations (C ,format = Format .FORWARDREF )["x" ]
1833+
1834+ with self .assertRaises (NotImplementedError ):
1835+ fwdref .evaluate (format = Format .VALUE_WITH_FAKE_GLOBALS )
1836+
1837+ with self .assertRaises (NotImplementedError ):
1838+ # Some other unsupported value
1839+ fwdref .evaluate (format = 7 )
1840+
17961841def test_evaluate_with_type_params (self ):
17971842class Gen [T ]:
17981843alias = int
@@ -1926,6 +1971,11 @@ def test_fwdref_invalid_syntax(self):
19261971with self .assertRaises (SyntaxError ):
19271972fr .evaluate ()
19281973
1974+ def test_fwdref_final_class (self ):
1975+ with self .assertRaises (TypeError ):
1976+ class C (ForwardRef ):
1977+ pass
1978+
19291979
19301980class TestAnnotationLib (unittest .TestCase ):
19311981def test__all__ (self ):