@@ -8469,6 +8469,10 @@ def test_pep_695_generics_with_future_annotations_nested_in_function(self):
84698469 )
84708470
84718471class TestEvaluateForwardRefs (BaseTestCase ):
8472+ def test_global_constant (self ):
8473+ if sys .version_info [:3 ] > (3 , 10 , 0 ):
8474+ self .assertTrue (_FORWARD_REF_HAS_CLASS )
8475+
84728476 def test_forward_ref_fallback (self ):
84738477 with self .assertRaises (NameError ):
84748478 evaluate_forward_ref (typing .ForwardRef ("doesntexist" ))
@@ -8637,19 +8641,25 @@ class Y(Generic[Tx]):
86378641 self .assertEqual (get_args (evaluated_ref3 ), (Z [str ],))
86388642
86398643 def test_invalid_special_forms (self ):
8640- # tests _lax_type_check to (not) raise error similar to the typing module
8644+ # tests _lax_type_check to raise errors the same way as the typing module.
86418645 with self .assertRaisesRegex (TypeError , "Plain" ):
86428646 evaluate_forward_ref (typing .ForwardRef ("Protocol" ), globals = vars (typing ))
86438647 with self .assertRaisesRegex (TypeError , "Plain" ):
86448648 evaluate_forward_ref (typing .ForwardRef ("Generic" ), globals = vars (typing ))
8649+ with self .assertRaisesRegex (TypeError , "Plain" ):
8650+ evaluate_forward_ref (typing .ForwardRef ("Final" ), globals = vars (typing ))
8651+ with self .assertRaisesRegex (TypeError , "Plain" ):
8652+ evaluate_forward_ref (typing .ForwardRef ("ClassVar" ), globals = vars (typing ))
86458653 if _FORWARD_REF_HAS_CLASS :
86468654 self .assertIs (evaluate_forward_ref (typing .ForwardRef ("Final" , is_class = True ), globals = vars (typing )), Final )
8655+ self .assertIs (evaluate_forward_ref (typing .ForwardRef ("ClassVar" , is_class = True ), globals = vars (typing )), ClassVar )
86478656 with self .assertRaisesRegex (TypeError , "Plain" ):
8648- evaluate_forward_ref (typing .ForwardRef ("Final" ), globals = vars (typing ))
8657+ evaluate_forward_ref (typing .ForwardRef ("Final" , is_argument = False ), globals = vars (typing ))
8658+ with self .assertRaisesRegex (TypeError , "Plain" ):
8659+ evaluate_forward_ref (typing .ForwardRef ("ClassVar" , is_argument = False ), globals = vars (typing ))
86498660 else :
86508661 self .assertIs (evaluate_forward_ref (typing .ForwardRef ("Final" , is_argument = False ), globals = vars (typing )), Final )
8651- with self .assertRaisesRegex (TypeError , "Plain" ):
8652- evaluate_forward_ref (typing .ForwardRef ("Final" ), globals = vars (typing ))
8662+ self .assertIs (evaluate_forward_ref (typing .ForwardRef ("ClassVar" , is_argument = False ), globals = vars (typing )), ClassVar )
86538663
86548664
86558665if __name__ == '__main__' :
0 commit comments