@@ -41,6 +41,51 @@ class {0}(metaclass=Meta):
41
41
"""
42
42
TYPING_MEMBERS = set (typing .__all__ )
43
43
44
+ TYPING_ALIAS = frozenset (
45
+ (
46
+ "typing.Hashable" ,
47
+ "typing.Awaitable" ,
48
+ "typing.Coroutine" ,
49
+ "typing.AsyncIterable" ,
50
+ "typing.AsyncIterator" ,
51
+ "typing.Iterable" ,
52
+ "typing.Iterator" ,
53
+ "typing.Reversible" ,
54
+ "typing.Sized" ,
55
+ "typing.Container" ,
56
+ "typing.Collection" ,
57
+ "typing.Callable" ,
58
+ "typing.AbstractSet" ,
59
+ "typing.MutableSet" ,
60
+ "typing.Mapping" ,
61
+ "typing.MutableMapping" ,
62
+ "typing.Sequence" ,
63
+ "typing.MutableSequence" ,
64
+ "typing.ByteString" ,
65
+ "typing.Tuple" ,
66
+ "typing.List" ,
67
+ "typing.Deque" ,
68
+ "typing.Set" ,
69
+ "typing.FrozenSet" ,
70
+ "typing.MappingView" ,
71
+ "typing.KeysView" ,
72
+ "typing.ItemsView" ,
73
+ "typing.ValuesView" ,
74
+ "typing.ContextManager" ,
75
+ "typing.AsyncContextManager" ,
76
+ "typing.Dict" ,
77
+ "typing.DefaultDict" ,
78
+ "typing.OrderedDict" ,
79
+ "typing.Counter" ,
80
+ "typing.ChainMap" ,
81
+ "typing.Generator" ,
82
+ "typing.AsyncGenerator" ,
83
+ "typing.Type" ,
84
+ "typing.Pattern" ,
85
+ "typing.Match" ,
86
+ )
87
+ )
88
+
44
89
45
90
def looks_like_typing_typevar_or_newtype (node ):
46
91
func = node .func
@@ -86,7 +131,7 @@ def infer_typing_attr(node, context=None):
86
131
except InferenceError as exc :
87
132
raise UseInferenceDefault from exc
88
133
89
- if not value .qname ().startswith ("typing." ):
134
+ if not value .qname ().startswith ("typing." ) or value . qname () in TYPING_ALIAS :
90
135
raise UseInferenceDefault
91
136
92
137
node = extract_node (TYPING_TYPE_TEMPLATE .format (value .qname ().split ("." )[- 1 ]))
@@ -161,7 +206,6 @@ def infer_typing_alias(
161
206
class_def = nodes .ClassDef (
162
207
name = assign_name .name ,
163
208
lineno = assign_name .lineno ,
164
- # tolineno=assign_name.lineno,
165
209
col_offset = assign_name .col_offset ,
166
210
parent = node .parent ,
167
211
)
@@ -198,10 +242,9 @@ def infer_typing_alias(
198
242
inference_tip (infer_typing_typevar_or_newtype ),
199
243
looks_like_typing_typevar_or_newtype ,
200
244
)
201
- if not PY37 :
202
- MANAGER .register_transform (
203
- nodes .Subscript , inference_tip (infer_typing_attr ), _looks_like_typing_subscript
204
- )
245
+ MANAGER .register_transform (
246
+ nodes .Subscript , inference_tip (infer_typing_attr ), _looks_like_typing_subscript
247
+ )
205
248
206
249
if PY39 :
207
250
MANAGER .register_transform (
0 commit comments