Skip to content

Commit 20adb54

Browse files
authored
Add typing to NodeNG._infer and associated nodes (#1541)
1 parent 9b114ad commit 20adb54

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

astroid/inference.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,13 @@
4848
# .infer method ###############################################################
4949

5050

51-
def infer_end(self, context=None):
51+
_T = TypeVar("_T")
52+
_BaseContainerT = TypeVar("_BaseContainerT", bound=nodes.BaseContainer)
53+
54+
55+
def infer_end(
56+
self: _T, context: InferenceContext | None = None, **kwargs: Any
57+
) -> Iterator[_T]:
5258
"""Inference's end for nodes that yield themselves on inference
5359
5460
These are objects for which inference does not have any semantic,
@@ -57,7 +63,7 @@ def infer_end(self, context=None):
5763
yield self
5864

5965

60-
# We add ignores to all these assignments in this file
66+
# We add ignores to all assignments to methods
6167
# See https://github.com/python/mypy/issues/2427
6268
nodes.Module._infer = infer_end # type: ignore[assignment]
6369
nodes.ClassDef._infer = infer_end # type: ignore[assignment]
@@ -89,7 +95,11 @@ def _infer_sequence_helper(node, context=None):
8995

9096

9197
@decorators.raise_if_nothing_inferred
92-
def infer_sequence(self, context=None):
98+
def infer_sequence(
99+
self: _BaseContainerT,
100+
context: InferenceContext | None = None,
101+
**kwargs: Any,
102+
) -> Iterator[_BaseContainerT]:
93103
has_starred_named_expr = any(
94104
isinstance(e, (nodes.Starred, nodes.NamedExpr)) for e in self.elts
95105
)

astroid/nodes/node_classes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4876,7 +4876,7 @@ def __init__(
48764876
)
48774877

48784878
def _infer(
4879-
self, context: InferenceContext | None = None
4879+
self, context: InferenceContext | None = None, **kwargs: Any
48804880
) -> Iterator[NodeNG | type[util.Uninferable]]:
48814881
yield self.value
48824882

astroid/nodes/node_ng.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,9 @@ def _infer_name(self, frame, name):
594594
# overridden for ImportFrom, Import, Global, TryExcept and Arguments
595595
pass
596596

597-
def _infer(self, context=None):
597+
def _infer(
598+
self, context: InferenceContext | None = None, **kwargs: Any
599+
) -> Iterator[NodeNG | type[util.Uninferable] | bases.Instance]:
598600
"""we don't know how to resolve a statement by default"""
599601
# this method is overridden by most concrete classes
600602
raise InferenceError(

astroid/objects.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import sys
1717
from collections.abc import Iterator
18-
from typing import TypeVar
18+
from typing import Any, TypeVar
1919

2020
from astroid import bases, decorators, util
2121
from astroid.context import InferenceContext
@@ -44,7 +44,7 @@ class FrozenSet(node_classes.BaseContainer):
4444
def pytype(self):
4545
return "builtins.frozenset"
4646

47-
def _infer(self, context=None):
47+
def _infer(self, context=None, **kwargs: Any):
4848
yield self
4949

5050
@cached_property
@@ -77,7 +77,7 @@ def __init__(self, mro_pointer, mro_type, self_class, scope):
7777
self._scope = scope
7878
super().__init__()
7979

80-
def _infer(self, context=None):
80+
def _infer(self, context=None, **kwargs: Any):
8181
yield self
8282

8383
def super_mro(self):
@@ -331,5 +331,7 @@ def pytype(self):
331331
def infer_call_result(self, caller=None, context=None):
332332
raise InferenceError("Properties are not callable")
333333

334-
def _infer(self: _T, context: InferenceContext | None = None) -> Iterator[_T]:
334+
def _infer(
335+
self: _T, context: InferenceContext | None = None, **kwargs: Any
336+
) -> Iterator[_T]:
335337
yield self

0 commit comments

Comments
 (0)