@@ -8300,20 +8300,29 @@ class Y(Generic[T_in_G], _EasyStr):
83008300 Format .FORWARDREF : TypeError ,
83018301 Format .STRING : "Protocol" ,
83028302 },
8303- Final : [ # plain usage of Final
8304- {
8305- "skip_if" : {"is_class" : False },
8306- Format .VALUE : Final ,
8307- Format .FORWARDREF : Final ,
8308- Format .STRING : Final ,
8309- },
8310- {
8311- "skip_if" : {"is_class" : True },
8312- Format .VALUE : TypeError ,
8313- Format .FORWARDREF : TypeError ,
8314- Format .STRING : Final ,
8315- },
8316- ],
8303+ Final : (
8304+ [ # plain usage of Final
8305+ {
8306+ "skip_if" : {"is_class" : False },
8307+ Format .VALUE : Final ,
8308+ Format .FORWARDREF : Final ,
8309+ Format .STRING : str (Final ),
8310+ },
8311+ {
8312+ "skip_if" : {"is_class" : True },
8313+ Format .VALUE : TypeError ,
8314+ Format .FORWARDREF : TypeError ,
8315+ Format .STRING : str (Final ),
8316+ },
8317+ ]
8318+ if _FORWARD_REF_HAS_CLASS
8319+ else Final # no errors here
8320+ ),
8321+ Generic : {
8322+ Format .VALUE : TypeError ,
8323+ Format .FORWARDREF : TypeError ,
8324+ Format .STRING : "Generic" ,
8325+ },
83178326 Union [str , None , "str" ]: {
83188327 Format .VALUE : Optional [str ],
83198328 Format .FORWARDREF : Optional [str ],
@@ -8340,6 +8349,8 @@ def _unroll_subcase(
83408349 ):
83418350 type_params = expected .get ("type_params" , None )
83428351 skip_if = expected .get ("skip_if" , False )
8352+ if format not in expected :
8353+ return
83438354 if skip_if :
83448355 L = locals ()
83458356 skip = all (
@@ -8411,17 +8422,17 @@ def unroll_cases(cases, outer_locals):
84118422 ),
84128423 )
84138424 else :
8425+ # NOTE: only for non-dict inputs
84148426 # Change expected to TypeError if it will fail typing._type_check
8415- if not inspect .isclass (expected ):
8427+ if format != Format . STRING and not inspect .isclass (expected ):
84168428 invalid_generic_forms = (Generic , Protocol )
8417- if not is_class :
8429+ if is_class is False :
84188430 invalid_generic_forms += (ClassVar ,)
84198431 if is_argument :
84208432 invalid_generic_forms += (Final ,)
8421- if (
8422- format != Format .STRING
8423- and get_origin (expected ) in invalid_generic_forms
8424- ):
8433+ elif not _FORWARD_REF_HAS_CLASS and is_argument :
8434+ invalid_generic_forms += (ClassVar , Final ,)
8435+ if get_origin (expected ) in invalid_generic_forms :
84258436 expected = TypeError
84268437 type_params = None
84278438 yield (
@@ -8450,12 +8461,6 @@ def unroll_cases(cases, outer_locals):
84508461 ref = typing .ForwardRef (annot , is_argument = is_argument , is_class = is_class )
84518462 else :
84528463 ref = typing .ForwardRef (annot , is_argument = is_argument )
8453- expected_orig = expected
8454- orig_globalns = globalns
8455- orig_localns = localns
8456- expected = expected_orig
8457- globalns = orig_globalns
8458- localns = orig_localns
84598464 with self .subTest (
84608465 format = format ,
84618466 ref = ref ,
0 commit comments