@@ -277,7 +277,8 @@ def infer_import(
277
277
** kwargs : Any ,
278
278
) -> Generator [nodes .Module , None , None ]:
279
279
"""infer an Import node: return the imported module/object"""
280
- context = context or InferenceContext ()
280
+ if not context :
281
+ raise InferenceError (node = self , context = context )
281
282
name = context .lookupname
282
283
if name is None :
283
284
raise InferenceError (node = self , context = context )
@@ -303,7 +304,8 @@ def infer_import_from(
303
304
** kwargs : Any ,
304
305
) -> Generator [InferenceResult , None , None ]:
305
306
"""infer a ImportFrom node: return the imported module/object"""
306
- context = context or InferenceContext ()
307
+ if not context :
308
+ raise InferenceError (node = self , context = context )
307
309
name = context .lookupname
308
310
if name is None :
309
311
raise InferenceError (node = self , context = context )
@@ -332,19 +334,18 @@ def infer_import_from(
332
334
nodes .ImportFrom ._infer = infer_import_from # type: ignore[assignment]
333
335
334
336
335
- @decorators .raise_if_nothing_inferred
336
- def infer_attribute (
337
- self : nodes .Attribute | nodes .AssignAttr ,
338
- context : InferenceContext | None = None ,
339
- ** kwargs : Any ,
340
- ) -> Generator [InferenceResult , None , InferenceErrorInfo ]:
337
+ def infer_attribute (self , context = None ):
341
338
"""infer an Attribute node by using getattr on the associated object"""
342
339
for owner in self .expr .infer (context ):
343
340
if owner is util .Uninferable :
344
341
yield owner
345
342
continue
346
343
347
- context = copy_context (context )
344
+ if not context :
345
+ context = InferenceContext ()
346
+ else :
347
+ context = copy_context (context )
348
+
348
349
old_boundnode = context .boundnode
349
350
try :
350
351
context .boundnode = owner
@@ -357,20 +358,20 @@ def infer_attribute(
357
358
pass
358
359
finally :
359
360
context .boundnode = old_boundnode
360
- return InferenceErrorInfo (node = self , context = context )
361
+ return dict (node = self , context = context )
361
362
362
363
363
- nodes .Attribute ._infer = decorators .path_wrapper (infer_attribute ) # type: ignore[assignment]
364
+ nodes .Attribute ._infer = decorators .raise_if_nothing_inferred (
365
+ decorators .path_wrapper (infer_attribute )
366
+ )
364
367
# won't work with a path wrapper
365
- nodes .AssignAttr .infer_lhs = infer_attribute
368
+ nodes .AssignAttr .infer_lhs = decorators . raise_if_nothing_inferred ( infer_attribute )
366
369
367
370
368
371
@decorators .raise_if_nothing_inferred
369
372
@decorators .path_wrapper
370
- def infer_global (
371
- self : nodes .Global , context : InferenceContext | None = None , ** kwargs : Any
372
- ) -> Generator [InferenceResult , None , None ]:
373
- if context is None or context .lookupname is None :
373
+ def infer_global (self , context = None ):
374
+ if context .lookupname is None :
374
375
raise InferenceError (node = self , context = context )
375
376
try :
376
377
return bases ._infer_stmts (self .root ().getattr (context .lookupname ), context )
@@ -386,10 +387,7 @@ def infer_global(
386
387
_SUBSCRIPT_SENTINEL = object ()
387
388
388
389
389
- @decorators .raise_if_nothing_inferred
390
- def infer_subscript (
391
- self : nodes .Subscript , context : InferenceContext | None = None , ** kwargs : Any
392
- ) -> Generator [InferenceResult , None , InferenceErrorInfo | None ]:
390
+ def infer_subscript (self , context = None ):
393
391
"""Inference for subscripts
394
392
395
393
We're understanding if the index is a Const
@@ -441,12 +439,14 @@ def infer_subscript(
441
439
found_one = True
442
440
443
441
if found_one :
444
- return InferenceErrorInfo (node = self , context = context )
442
+ return dict (node = self , context = context )
445
443
return None
446
444
447
445
448
- nodes .Subscript ._infer = decorators .path_wrapper (infer_subscript ) # type: ignore[assignment]
449
- nodes .Subscript .infer_lhs = infer_subscript
446
+ nodes .Subscript ._infer = decorators .raise_if_nothing_inferred ( # type: ignore[assignment]
447
+ decorators .path_wrapper (infer_subscript )
448
+ )
449
+ nodes .Subscript .infer_lhs = decorators .raise_if_nothing_inferred (infer_subscript )
450
450
451
451
452
452
@decorators .raise_if_nothing_inferred
@@ -981,7 +981,8 @@ def _infer_augassign(
981
981
self : nodes .AugAssign , context : InferenceContext | None = None
982
982
) -> Generator [InferenceResult | util .BadBinaryOperationMessage , None , None ]:
983
983
"""Inference logic for augmented binary operations."""
984
- context = context or InferenceContext ()
984
+ if context is None :
985
+ context = InferenceContext ()
985
986
986
987
rhs_context = context .clone ()
987
988
0 commit comments