|
8 | 8 |
|
9 | 9 | from astroid import context, extract_node, inference_tip
|
10 | 10 | from astroid.builder import _extract_single_node
|
11 |
| -from astroid.const import PY37_PLUS, PY38_PLUS, PY39_PLUS |
| 11 | +from astroid.const import PY38_PLUS, PY39_PLUS |
12 | 12 | from astroid.exceptions import (
|
13 | 13 | AttributeInferenceError,
|
14 | 14 | InferenceError,
|
@@ -148,22 +148,16 @@ def infer_typing_attr(
|
148 | 148 | except (InferenceError, StopIteration) as exc:
|
149 | 149 | raise UseInferenceDefault from exc
|
150 | 150 |
|
151 |
| - if ( |
152 |
| - not value.qname().startswith("typing.") |
153 |
| - or PY37_PLUS |
154 |
| - and value.qname() in TYPING_ALIAS |
155 |
| - ): |
156 |
| - # If typing subscript belongs to an alias |
157 |
| - # (PY37+) handle it separately. |
| 151 | + if not value.qname().startswith("typing.") or value.qname() in TYPING_ALIAS: |
| 152 | + # If typing subscript belongs to an alias handle it separately. |
158 | 153 | raise UseInferenceDefault
|
159 | 154 |
|
160 |
| - if ( |
161 |
| - PY37_PLUS |
162 |
| - and isinstance(value, ClassDef) |
163 |
| - and value.qname() |
164 |
| - in {"typing.Generic", "typing.Annotated", "typing_extensions.Annotated"} |
165 |
| - ): |
166 |
| - # With PY37+ typing.Generic and typing.Annotated (PY39) are subscriptable |
| 155 | + if isinstance(value, ClassDef) and value.qname() in { |
| 156 | + "typing.Generic", |
| 157 | + "typing.Annotated", |
| 158 | + "typing_extensions.Annotated", |
| 159 | + }: |
| 160 | + # typing.Generic and typing.Annotated (PY39) are subscriptable |
167 | 161 | # through __class_getitem__. Since astroid can't easily
|
168 | 162 | # infer the native methods, replace them for an easy inference tip
|
169 | 163 | func_to_add = _extract_single_node(CLASS_GETITEM_TEMPLATE)
|
@@ -424,10 +418,9 @@ def infer_typing_cast(
|
424 | 418 | ClassDef, inference_tip(infer_old_typedDict), _looks_like_typedDict
|
425 | 419 | )
|
426 | 420 |
|
427 |
| -if PY37_PLUS: |
428 |
| - AstroidManager().register_transform( |
429 |
| - Call, inference_tip(infer_typing_alias), _looks_like_typing_alias |
430 |
| - ) |
431 |
| - AstroidManager().register_transform( |
432 |
| - Call, inference_tip(infer_special_alias), _looks_like_special_alias |
433 |
| - ) |
| 421 | +AstroidManager().register_transform( |
| 422 | + Call, inference_tip(infer_typing_alias), _looks_like_typing_alias |
| 423 | +) |
| 424 | +AstroidManager().register_transform( |
| 425 | + Call, inference_tip(infer_special_alias), _looks_like_special_alias |
| 426 | +) |
0 commit comments