File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -1675,6 +1675,21 @@ def test_name_lookup_without_eval(self):
16751675
16761676 self .assertEqual (exc .exception .name , "doesntexist" )
16771677
1678+ def test_evaluate_undefined_generic (self ):
1679+ # Test the codepath where have to eval() with undefined variables.
1680+ fwdref = ForwardRef ("glob[int, undef]" ).evaluate (format = Format .FORWARDREF , globals = {"glob" : dict })
1681+ self .assertIs (fwdref .__origin__ , dict )
1682+ self .assertIs (fwdref .__args__ [0 ], int )
1683+
1684+ fwdref = ForwardRef ("loc[int, undef]" ).evaluate (format = Format .FORWARDREF , locals = {"loc" : dict })
1685+ self .assertIs (fwdref .__origin__ , dict )
1686+ self .assertIs (fwdref .__args__ [0 ], int )
1687+
1688+ # Ensure that globals overwrite builtins
1689+ fwdref = ForwardRef ("list[int, undef]" ).evaluate (format = Format .FORWARDREF , globals = {"list" : dict })
1690+ self .assertIs (fwdref .__origin__ , dict )
1691+ self .assertIs (fwdref .__args__ [0 ], int )
1692+
16781693 def test_fwdref_invalid_syntax (self ):
16791694 fr = ForwardRef ("if" )
16801695 with self .assertRaises (SyntaxError ):
You can’t perform that action at this time.
0 commit comments