@@ -1677,21 +1677,29 @@ def test_name_lookup_without_eval(self):
16771677
16781678 def test_evaluate_undefined_generic (self ):
16791679 # Test the codepath where have to eval() with undefined variables.
1680- generic = ForwardRef ("glob[int, undef]" ).evaluate (format = Format .FORWARDREF , globals = {"glob" : dict })
1681- self .assertNotIsInstance (generic , ForwardRef )
1682- self .assertIs (generic .__origin__ , dict )
1683- self .assertIs (generic .__args__ [0 ], int )
1680+ class C :
1681+ x : alias [int , undef ]
16841682
1685- generic = ForwardRef ("loc[int, undef]" ).evaluate (format = Format .FORWARDREF , locals = {"loc" : dict })
1683+ generic = get_annotations (C , format = Format .FORWARDREF )["x" ].evaluate (
1684+ format = Format .FORWARDREF ,
1685+ globals = {"alias" : dict }
1686+ )
16861687 self .assertNotIsInstance (generic , ForwardRef )
16871688 self .assertIs (generic .__origin__ , dict )
1689+ self .assertEqual (len (generic .__args__ ), 2 )
16881690 self .assertIs (generic .__args__ [0 ], int )
1691+ self .assertIsInstance (generic .__args__ [1 ], ForwardRef )
16891692
1690- # Ensure that globals overwrite builtins
1691- generic = ForwardRef ("list[int, undef]" ).evaluate (format = Format .FORWARDREF , globals = {"list" : dict })
1693+ generic = get_annotations (C , format = Format .FORWARDREF )["x" ].evaluate (
1694+ format = Format .FORWARDREF ,
1695+ globals = {"alias" : Union },
1696+ locals = {"alias" : dict }
1697+ )
16921698 self .assertNotIsInstance (generic , ForwardRef )
16931699 self .assertIs (generic .__origin__ , dict )
1700+ self .assertEqual (len (generic .__args__ ), 2 )
16941701 self .assertIs (generic .__args__ [0 ], int )
1702+ self .assertIsInstance (generic .__args__ [1 ], ForwardRef )
16951703
16961704 def test_fwdref_invalid_syntax (self ):
16971705 fr = ForwardRef ("if" )
0 commit comments