@@ -455,15 +455,31 @@ def _extract_class_dict(cls):
455455
456456if sys .version_info [:2 ] < (3 , 7 ): # pragma: no branch
457457 def _is_parametrized_type_hint (obj ):
458- # This is very cheap but might generate false positives.
458+ # This is very cheap but might generate false positives. So try to
459+ # narrow it down is good as possible.
460+ type_module = getattr (type (obj ), '__module__' , None )
461+ from_typing_extensions = type_module == 'typing_extensions'
462+ from_typing = type_module == 'typing'
463+
459464 # general typing Constructs
460465 is_typing = getattr (obj , '__origin__' , None ) is not None
461466
462467 # typing_extensions.Literal
463- is_literal = getattr (obj , '__values__' , None ) is not None
468+ is_literal = (
469+ (getattr (obj , '__values__' , None ) is not None )
470+ and from_typing_extensions
471+ )
464472
465473 # typing_extensions.Final
466- is_final = getattr (obj , '__type__' , None ) is not None
474+ is_final = (
475+ (getattr (obj , '__type__' , None ) is not None )
476+ and from_typing_extensions
477+ )
478+
479+ # typing.ClassVar
480+ is_classvar = (
481+ (getattr (obj , '__type__' , None ) is not None ) and from_typing
482+ )
467483
468484 # typing.Union/Tuple for old Python 3.5
469485 is_union = getattr (obj , '__union_params__' , None ) is not None
@@ -472,8 +488,8 @@ def _is_parametrized_type_hint(obj):
472488 getattr (obj , '__result__' , None ) is not None and
473489 getattr (obj , '__args__' , None ) is not None
474490 )
475- return any ((is_typing , is_literal , is_final , is_union , is_tuple ,
476- is_callable ))
491+ return any ((is_typing , is_literal , is_final , is_classvar , is_union ,
492+ is_tuple , is_callable ))
477493
478494 def _create_parametrized_type_hint (origin , args ):
479495 return origin [args ]
0 commit comments