@@ -233,6 +233,8 @@ def infer_name(
233
233
234
234
235
235
# pylint: disable=no-value-for-parameter
236
+ # The order of the decorators here is important
237
+ # See https://github.com/PyCQA/astroid/commit/0a8a75db30da060a24922e05048bc270230f5
236
238
nodes .Name ._infer = decorators .raise_if_nothing_inferred ( # type: ignore[assignment]
237
239
decorators .path_wrapper (infer_name )
238
240
)
@@ -277,8 +279,7 @@ def infer_import(
277
279
** kwargs : Any ,
278
280
) -> Generator [nodes .Module , None , None ]:
279
281
"""infer an Import node: return the imported module/object"""
280
- if not context :
281
- raise InferenceError (node = self , context = context )
282
+ context = context or InferenceContext ()
282
283
name = context .lookupname
283
284
if name is None :
284
285
raise InferenceError (node = self , context = context )
@@ -304,8 +305,7 @@ def infer_import_from(
304
305
** kwargs : Any ,
305
306
) -> Generator [InferenceResult , None , None ]:
306
307
"""infer a ImportFrom node: return the imported module/object"""
307
- if not context :
308
- raise InferenceError (node = self , context = context )
308
+ context = context or InferenceContext ()
309
309
name = context .lookupname
310
310
if name is None :
311
311
raise InferenceError (node = self , context = context )
@@ -334,18 +334,18 @@ def infer_import_from(
334
334
nodes .ImportFrom ._infer = infer_import_from # type: ignore[assignment]
335
335
336
336
337
- def infer_attribute (self , context = None ):
337
+ def infer_attribute (
338
+ self : nodes .Attribute | nodes .AssignAttr ,
339
+ context : InferenceContext | None = None ,
340
+ ** kwargs : Any ,
341
+ ) -> Generator [InferenceResult , None , InferenceErrorInfo ]:
338
342
"""infer an Attribute node by using getattr on the associated object"""
339
343
for owner in self .expr .infer (context ):
340
344
if owner is util .Uninferable :
341
345
yield owner
342
346
continue
343
347
344
- if not context :
345
- context = InferenceContext ()
346
- else :
347
- context = copy_context (context )
348
-
348
+ context = copy_context (context )
349
349
old_boundnode = context .boundnode
350
350
try :
351
351
context .boundnode = owner
@@ -358,10 +358,12 @@ def infer_attribute(self, context=None):
358
358
pass
359
359
finally :
360
360
context .boundnode = old_boundnode
361
- return dict (node = self , context = context )
361
+ return InferenceErrorInfo (node = self , context = context )
362
362
363
363
364
- nodes .Attribute ._infer = decorators .raise_if_nothing_inferred (
364
+ # The order of the decorators here is important
365
+ # See https://github.com/PyCQA/astroid/commit/0a8a75db30da060a24922e05048bc270230f5
366
+ nodes .Attribute ._infer = decorators .raise_if_nothing_inferred ( # type: ignore[assignment]
365
367
decorators .path_wrapper (infer_attribute )
366
368
)
367
369
# won't work with a path wrapper
@@ -370,8 +372,10 @@ def infer_attribute(self, context=None):
370
372
371
373
@decorators .raise_if_nothing_inferred
372
374
@decorators .path_wrapper
373
- def infer_global (self , context = None ):
374
- if context .lookupname is None :
375
+ def infer_global (
376
+ self : nodes .Global , context : InferenceContext | None = None , ** kwargs : Any
377
+ ) -> Generator [InferenceResult , None , None ]:
378
+ if context is None or context .lookupname is None :
375
379
raise InferenceError (node = self , context = context )
376
380
try :
377
381
return bases ._infer_stmts (self .root ().getattr (context .lookupname ), context )
@@ -387,7 +391,9 @@ def infer_global(self, context=None):
387
391
_SUBSCRIPT_SENTINEL = object ()
388
392
389
393
390
- def infer_subscript (self , context = None ):
394
+ def infer_subscript (
395
+ self : nodes .Subscript , context : InferenceContext | None = None , ** kwargs : Any
396
+ ) -> Generator [InferenceResult , None , InferenceErrorInfo | None ]:
391
397
"""Inference for subscripts
392
398
393
399
We're understanding if the index is a Const
@@ -439,10 +445,12 @@ def infer_subscript(self, context=None):
439
445
found_one = True
440
446
441
447
if found_one :
442
- return dict (node = self , context = context )
448
+ return InferenceErrorInfo (node = self , context = context )
443
449
return None
444
450
445
451
452
+ # The order of the decorators here is important
453
+ # See https://github.com/PyCQA/astroid/commit/0a8a75db30da060a24922e05048bc270230f5
446
454
nodes .Subscript ._infer = decorators .raise_if_nothing_inferred ( # type: ignore[assignment]
447
455
decorators .path_wrapper (infer_subscript )
448
456
)
@@ -981,8 +989,7 @@ def _infer_augassign(
981
989
self : nodes .AugAssign , context : InferenceContext | None = None
982
990
) -> Generator [InferenceResult | util .BadBinaryOperationMessage , None , None ]:
983
991
"""Inference logic for augmented binary operations."""
984
- if context is None :
985
- context = InferenceContext ()
992
+ context = context or InferenceContext ()
986
993
987
994
rhs_context = context .clone ()
988
995
0 commit comments