@@ -32,27 +32,29 @@ def get_annotation_class_name(annotation) -> str:
32
32
return 'None'
33
33
elif annotation is Any :
34
34
return 'Any'
35
+ elif annotation is AnyStr :
36
+ return 'AnyStr'
35
37
elif inspect .isfunction (annotation ) and hasattr (annotation , '__supertype__' ):
36
38
return 'NewType'
37
39
38
- if getattr (annotation , '__name__ ' , None ):
39
- return annotation .__name__
40
+ if getattr (annotation , '__qualname__ ' , None ):
41
+ return annotation .__qualname__
40
42
elif getattr (annotation , '_name' , None ): # Required for generic aliases on Python 3.7+
41
43
return annotation ._name
42
44
elif getattr (annotation , 'name' , None ): # Required for at least Pattern
43
45
return annotation .name
44
46
45
47
origin = getattr (annotation , '__origin__' , None )
46
48
if origin :
47
- if getattr (origin , '__name__ ' , None ): # Required for Protocol subclasses
48
- return origin .__name__
49
+ if getattr (origin , '__qualname__ ' , None ): # Required for Protocol subclasses
50
+ return origin .__qualname__
49
51
elif getattr (origin , '_name' , None ): # Required for Union on Python 3.7+
50
52
return origin ._name
51
53
else :
52
- return origin .__class__ .__name__ .lstrip ('_' ) # Required for Union on Python < 3.7
54
+ return origin .__class__ .__qualname__ .lstrip ('_' ) # Required for Union on Python < 3.7
53
55
54
56
annotation_cls = annotation if inspect .isclass (annotation ) else annotation .__class__
55
- return annotation_cls .__name__ .lstrip ('_' )
57
+ return annotation_cls .__qualname__ .lstrip ('_' )
56
58
57
59
58
60
def get_annotation_args (annotation , module : str , class_name : str ) -> Tuple :
0 commit comments