Skip to content

Commit c8c01ef

Browse files
committed
Remove all references to _infer
1 parent 75f0b08 commit c8c01ef

File tree

5 files changed

+11
-104
lines changed

5 files changed

+11
-104
lines changed

astroid/inference.py

+6-70
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,6 @@ def infer_end(
8686
yield self
8787

8888

89-
# We add ignores to all assignments to methods
90-
# See https://github.com/python/mypy/issues/2427
91-
nodes.Module._infer = infer_end
92-
nodes.ClassDef._infer = infer_end
93-
nodes.Lambda._infer = infer_end # type: ignore[assignment]
94-
nodes.Const._infer = infer_end # type: ignore[assignment]
95-
nodes.Slice._infer = infer_end # type: ignore[assignment]
96-
97-
9889
def _infer_sequence_helper(
9990
node: _BaseContainerT, context: InferenceContext | None = None
10091
) -> list[SuccessfulInferenceResult]:
@@ -140,11 +131,6 @@ def infer_sequence(
140131
yield self
141132

142133

143-
nodes.List._infer = infer_sequence # type: ignore[assignment]
144-
nodes.Tuple._infer = infer_sequence # type: ignore[assignment]
145-
nodes.Set._infer = infer_sequence # type: ignore[assignment]
146-
147-
148134
def infer_map(
149135
self: nodes.Dict, context: InferenceContext | None = None
150136
) -> Iterator[nodes.Dict]:
@@ -207,9 +193,6 @@ def _infer_map(
207193
return values
208194

209195

210-
nodes.Dict._infer = infer_map # type: ignore[assignment]
211-
212-
213196
def _higher_function_scope(node: nodes.NodeNG) -> nodes.FunctionDef | None:
214197
"""Search for the first function which encloses the given
215198
scope. This can be used for looking up in that function's
@@ -255,6 +238,8 @@ def infer_name(
255238
return bases._infer_stmts(stmts, context, frame)
256239

257240

241+
# The order of the decorators here is important
242+
# See https://github.com/pylint-dev/astroid/commit/0a8a75db30da060a24922e05048bc270230f5
258243
@decorators.raise_if_nothing_inferred
259244
@decorators.path_wrapper
260245
def _infer_name(
@@ -265,12 +250,6 @@ def _infer_name(
265250
return infer_name(self, context, **kwargs)
266251

267252

268-
# pylint: disable=no-value-for-parameter
269-
# The order of the decorators here is important
270-
# See https://github.com/pylint-dev/astroid/commit/0a8a75db30da060a24922e05048bc270230f5
271-
nodes.Name._infer = decorators.raise_if_nothing_inferred(
272-
decorators.path_wrapper(infer_name)
273-
)
274253
nodes.AssignName.infer_lhs = infer_name # won't work with a path wrapper
275254

276255

@@ -300,9 +279,6 @@ def infer_call(
300279
return InferenceErrorInfo(node=self, context=context)
301280

302281

303-
nodes.Call._infer = infer_call # type: ignore[assignment]
304-
305-
306282
@decorators.raise_if_nothing_inferred
307283
@decorators.path_wrapper
308284
def infer_import(
@@ -326,9 +302,6 @@ def infer_import(
326302
raise InferenceError(node=self, context=context) from exc
327303

328304

329-
nodes.Import._infer = infer_import
330-
331-
332305
@decorators.raise_if_nothing_inferred
333306
@decorators.path_wrapper
334307
def infer_import_from(
@@ -364,9 +337,6 @@ def infer_import_from(
364337
) from error
365338

366339

367-
nodes.ImportFrom._infer = infer_import_from # type: ignore[assignment]
368-
369-
370340
def infer_attribute(
371341
self: nodes.Attribute | nodes.AssignAttr,
372342
context: InferenceContext | None = None,
@@ -399,6 +369,8 @@ def infer_attribute(
399369
return InferenceErrorInfo(node=self, context=context)
400370

401371

372+
# The order of the decorators here is important
373+
# See https://github.com/pylint-dev/astroid/commit/0a8a75db30da060a24922e05048bc270230f5
402374
@decorators.raise_if_nothing_inferred
403375
@decorators.path_wrapper
404376
def _infer_attribute(
@@ -409,11 +381,6 @@ def _infer_attribute(
409381
return infer_attribute(self, context, **kwargs)
410382

411383

412-
# The order of the decorators here is important
413-
# See https://github.com/pylint-dev/astroid/commit/0a8a75db30da060a24922e05048bc270230f5
414-
nodes.Attribute._infer = decorators.raise_if_nothing_inferred(
415-
decorators.path_wrapper(infer_attribute)
416-
)
417384
# won't work with a path wrapper
418385
nodes.AssignAttr.infer_lhs = decorators.raise_if_nothing_inferred(infer_attribute)
419386

@@ -433,9 +400,6 @@ def infer_global(
433400
) from error
434401

435402

436-
nodes.Global._infer = infer_global # type: ignore[assignment]
437-
438-
439403
_SUBSCRIPT_SENTINEL = object()
440404

441405

@@ -498,6 +462,8 @@ def infer_subscript(
498462
return None
499463

500464

465+
# The order of the decorators here is important
466+
# See https://github.com/pylint-dev/astroid/commit/0a8a75db30da060a24922e05048bc270230f5
501467
@decorators.raise_if_nothing_inferred
502468
@decorators.path_wrapper
503469
def _infer_subscript(
@@ -506,11 +472,6 @@ def _infer_subscript(
506472
return infer_subscript(self, context=context, **kwargs)
507473

508474

509-
# The order of the decorators here is important
510-
# See https://github.com/pylint-dev/astroid/commit/0a8a75db30da060a24922e05048bc270230f5
511-
nodes.Subscript._infer = decorators.raise_if_nothing_inferred( # type: ignore[assignment]
512-
decorators.path_wrapper(infer_subscript)
513-
)
514475
nodes.Subscript.infer_lhs = decorators.raise_if_nothing_inferred(infer_subscript)
515476

516477

@@ -569,9 +530,6 @@ def _infer_boolop(
569530
return InferenceErrorInfo(node=self, context=context)
570531

571532

572-
nodes.BoolOp._infer = _infer_boolop
573-
574-
575533
# UnaryOp, BinOp and AugAssign inferences
576534

577535

@@ -668,7 +626,6 @@ def infer_unaryop(
668626

669627

670628
nodes.UnaryOp._infer_unaryop = _infer_unaryop
671-
nodes.UnaryOp._infer = infer_unaryop
672629

673630

674631
def _is_not_implemented(const) -> bool:
@@ -1020,7 +977,6 @@ def infer_binop(
1020977

1021978

1022979
nodes.BinOp._infer_binop = _infer_binop
1023-
nodes.BinOp._infer = infer_binop
1024980

1025981
COMPARE_OPS: dict[str, Callable[[Any, Any], bool]] = {
1026982
"==": operator.eq,
@@ -1118,9 +1074,6 @@ def _infer_compare(
11181074
yield nodes.Const(retval)
11191075

11201076

1121-
nodes.Compare._infer = _infer_compare # type: ignore[assignment]
1122-
1123-
11241077
def _infer_augassign(
11251078
self: nodes.AugAssign, context: InferenceContext | None = None
11261079
) -> Generator[InferenceResult | util.BadBinaryOperationMessage, None, None]:
@@ -1160,7 +1113,6 @@ def infer_augassign(
11601113

11611114

11621115
nodes.AugAssign._infer_augassign = _infer_augassign
1163-
nodes.AugAssign._infer = infer_augassign
11641116

11651117
# End of binary operation inference.
11661118

@@ -1174,9 +1126,6 @@ def infer_arguments(
11741126
return protocols._arguments_infer_argname(self, context.lookupname, context)
11751127

11761128

1177-
nodes.Arguments._infer = infer_arguments # type: ignore[assignment]
1178-
1179-
11801129
@decorators.raise_if_nothing_inferred
11811130
@decorators.path_wrapper
11821131
def infer_assign(
@@ -1194,10 +1143,6 @@ def infer_assign(
11941143
return bases._infer_stmts(stmts, context)
11951144

11961145

1197-
nodes.AssignName._infer = infer_assign
1198-
nodes.AssignAttr._infer = infer_assign
1199-
1200-
12011146
@decorators.raise_if_nothing_inferred
12021147
@decorators.path_wrapper
12031148
def infer_empty_node(
@@ -1214,9 +1159,6 @@ def infer_empty_node(
12141159
yield util.Uninferable
12151160

12161161

1217-
nodes.EmptyNode._infer = infer_empty_node # type: ignore[assignment]
1218-
1219-
12201162
def _populate_context_lookup(call: nodes.Call, context: InferenceContext | None):
12211163
# Allows context to be saved for later
12221164
# for inference inside a function
@@ -1269,9 +1211,6 @@ def infer_ifexp(
12691211
yield from self.orelse.infer(context=rhs_context)
12701212

12711213

1272-
nodes.IfExp._infer = infer_ifexp # type: ignore[assignment]
1273-
1274-
12751214
def infer_functiondef(
12761215
self: _FunctionDefT, context: InferenceContext | None = None, **kwargs: Any
12771216
) -> Generator[Property | _FunctionDefT, None, InferenceErrorInfo]:
@@ -1306,9 +1245,6 @@ def infer_functiondef(
13061245
return InferenceErrorInfo(node=self, context=context)
13071246

13081247

1309-
nodes.FunctionDef._infer = infer_functiondef
1310-
1311-
13121248
# pylint: disable-next=too-many-return-statements
13131249
def _infer_node(
13141250
node: nodes.NodeNG, context: InferenceContext | None = None, **kwargs: Any

astroid/nodes/node_classes.py

-9
Original file line numberDiff line numberDiff line change
@@ -3932,10 +3932,6 @@ def __init__(
39323932
def qname(self) -> Literal["Unknown"]:
39333933
return "Unknown"
39343934

3935-
def _infer(self, context: InferenceContext | None = None, **kwargs):
3936-
"""Inference on an Unknown node immediately terminates."""
3937-
yield util.Uninferable
3938-
39393935

39403936
class EvaluatedObject(NodeNG):
39413937
"""Contains an object that has already been inferred
@@ -3963,11 +3959,6 @@ def __init__(self, original: NodeNG, value: NodeNG | util.UninferableBase) -> No
39633959
end_col_offset=self.original.end_col_offset,
39643960
)
39653961

3966-
def _infer(
3967-
self, context: InferenceContext | None = None, **kwargs: Any
3968-
) -> Generator[NodeNG | util.UninferableBase, None, None]:
3969-
yield self.value
3970-
39713962

39723963
# Pattern matching #######################################################
39733964

astroid/nodes/node_ng.py

+1-11
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,13 @@
2626
from astroid.context import InferenceContext
2727
from astroid.exceptions import (
2828
AstroidError,
29-
InferenceError,
3029
ParentMissingError,
3130
StatementMissing,
3231
)
3332
from astroid.nodes.as_string import AsStringVisitor
3433
from astroid.nodes.const import OP_PRECEDENCE
3534
from astroid.nodes.utils import Position
36-
from astroid.typing import InferenceErrorInfo, InferenceResult, InferFn
35+
from astroid.typing import InferenceResult, InferFn
3736

3837
if TYPE_CHECKING:
3938
from astroid import nodes
@@ -537,15 +536,6 @@ def _infer_name(self, frame, name):
537536
# overridden for ImportFrom, Import, Global, TryExcept, TryStar and Arguments
538537
pass
539538

540-
def _infer(
541-
self, context: InferenceContext | None = None, **kwargs: Any
542-
) -> Generator[InferenceResult, None, InferenceErrorInfo | None]:
543-
"""We don't know how to resolve a statement by default."""
544-
# this method is overridden by most concrete classes
545-
raise InferenceError(
546-
"No inference function for {node!r}.", node=self, context=context
547-
)
548-
549539
def inferred(self):
550540
"""Get a list of the inferred values.
551541

astroid/objects.py

+2-13
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
from __future__ import annotations
1515

16-
from collections.abc import Generator, Iterator
16+
from collections.abc import Iterator
1717
from functools import cached_property
18-
from typing import Any, Literal, NoReturn, TypeVar
18+
from typing import Literal, NoReturn, TypeVar
1919

2020
from astroid import bases, decorators, util
2121
from astroid.context import InferenceContext
@@ -39,9 +39,6 @@ class FrozenSet(node_classes.BaseContainer):
3939
def pytype(self) -> Literal["builtins.frozenset"]:
4040
return "builtins.frozenset"
4141

42-
def _infer(self, context: InferenceContext | None = None, **kwargs: Any):
43-
yield self
44-
4542
@cached_property
4643
def _proxied(self): # pylint: disable=method-hidden
4744
ast_builtins = AstroidManager().builtins_module
@@ -84,9 +81,6 @@ def __init__(
8481
end_col_offset=scope.end_col_offset,
8582
)
8683

87-
def _infer(self, context: InferenceContext | None = None, **kwargs: Any):
88-
yield self
89-
9084
def super_mro(self):
9185
"""Get the MRO which will be used to lookup attributes in this super."""
9286
if not isinstance(self.mro_pointer, scoped_nodes.ClassDef):
@@ -366,8 +360,3 @@ def infer_call_result(
366360
context: InferenceContext | None = None,
367361
) -> NoReturn:
368362
raise InferenceError("Properties are not callable")
369-
370-
def _infer(
371-
self: _T, context: InferenceContext | None = None, **kwargs: Any
372-
) -> Generator[_T, None, None]:
373-
yield self

tests/test_inference.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
NotFoundError,
4141
)
4242
from astroid.inference import infer_end as inference_infer_end
43+
from astroid.inference import infer_object
4344
from astroid.objects import ExceptionInstance
4445

4546
from . import resources
@@ -7022,7 +7023,7 @@ def patch(cls):
70227023
def test_function_def_cached_generator() -> None:
70237024
"""Regression test for https://github.com/pylint-dev/astroid/issues/817."""
70247025
funcdef: nodes.FunctionDef = extract_node("def func(): pass")
7025-
next(funcdef._infer())
7026+
next(infer_object(funcdef))
70267027

70277028

70287029
class TestOldStyleStringFormatting:

0 commit comments

Comments
 (0)