17
17
from functools import partial
18
18
19
19
from astroid import context , extract_node , inference_tip
20
+ from astroid .builder import _extract_single_node
20
21
from astroid .const import PY37_PLUS , PY38_PLUS , PY39_PLUS
21
22
from astroid .exceptions import (
22
23
AttributeInferenceError ,
@@ -171,7 +172,7 @@ def infer_typing_attr(
171
172
# With PY37+ typing.Generic and typing.Annotated (PY39) are subscriptable
172
173
# through __class_getitem__. Since astroid can't easily
173
174
# infer the native methods, replace them for an easy inference tip
174
- func_to_add = extract_node (CLASS_GETITEM_TEMPLATE )
175
+ func_to_add = _extract_single_node (CLASS_GETITEM_TEMPLATE )
175
176
value .locals ["__class_getitem__" ] = [func_to_add ]
176
177
if (
177
178
isinstance (node .parent , ClassDef )
@@ -199,7 +200,7 @@ def _looks_like_typedDict( # pylint: disable=invalid-name
199
200
def infer_old_typedDict ( # pylint: disable=invalid-name
200
201
node : ClassDef , ctx : typing .Optional [context .InferenceContext ] = None
201
202
) -> typing .Iterator [ClassDef ]:
202
- func_to_add = extract_node ("dict" )
203
+ func_to_add = _extract_single_node ("dict" )
203
204
node .locals ["__call__" ] = [func_to_add ]
204
205
return iter ([node ])
205
206
@@ -215,7 +216,7 @@ def infer_typedDict( # pylint: disable=invalid-name
215
216
parent = node .parent ,
216
217
)
217
218
class_def .postinit (bases = [extract_node ("dict" )], body = [], decorators = None )
218
- func_to_add = extract_node ("dict" )
219
+ func_to_add = _extract_single_node ("dict" )
219
220
class_def .locals ["__call__" ] = [func_to_add ]
220
221
return iter ([class_def ])
221
222
@@ -308,7 +309,7 @@ def infer_typing_alias(
308
309
and maybe_type_var .value > 0
309
310
):
310
311
# If typing alias is subscriptable, add `__class_getitem__` to ClassDef
311
- func_to_add = extract_node (CLASS_GETITEM_TEMPLATE )
312
+ func_to_add = _extract_single_node (CLASS_GETITEM_TEMPLATE )
312
313
class_def .locals ["__class_getitem__" ] = [func_to_add ]
313
314
else :
314
315
# If not, make sure that `__class_getitem__` access is forbidden.
@@ -373,7 +374,7 @@ def infer_special_alias(
373
374
parent = node .parent ,
374
375
)
375
376
class_def .postinit (bases = [res ], body = [], decorators = None )
376
- func_to_add = extract_node (CLASS_GETITEM_TEMPLATE )
377
+ func_to_add = _extract_single_node (CLASS_GETITEM_TEMPLATE )
377
378
class_def .locals ["__class_getitem__" ] = [func_to_add ]
378
379
return iter ([class_def ])
379
380
0 commit comments