Skip to content

Commit 9aabf76

Browse files
committed
Define _infer instead of infer on subclasses of NodeNG
1 parent f125fa7 commit 9aabf76

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

astroid/nodes/node_classes.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
Callable,
1717
ClassVar,
1818
Generator,
19+
Iterator,
1920
Optional,
2021
Type,
2122
TypeVar,
@@ -4876,7 +4877,9 @@ def __init__(
48764877
parent=self.original.parent,
48774878
)
48784879

4879-
def infer(self, context=None, **kwargs):
4880+
def _infer(
4881+
self, context: Optional[InferenceContext] = None
4882+
) -> Iterator[Union[NodeNG, Type[util.Uninferable]]]:
48804883
yield self.value
48814884

48824885

astroid/objects.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
"""
1313

1414
import sys
15+
from typing import Iterator, Optional, TypeVar
1516

1617
from astroid import bases, decorators, util
18+
from astroid.context import InferenceContext
1719
from astroid.exceptions import (
1820
AttributeInferenceError,
1921
InferenceError,
@@ -30,6 +32,8 @@
3032
else:
3133
from astroid.decorators import cachedproperty as cached_property
3234

35+
_T = TypeVar("_T")
36+
3337

3438
class FrozenSet(node_classes.BaseContainer):
3539
"""class representing a FrozenSet composite node"""
@@ -324,5 +328,5 @@ def pytype(self):
324328
def infer_call_result(self, caller=None, context=None):
325329
raise InferenceError("Properties are not callable")
326330

327-
def infer(self, context=None, **kwargs):
328-
return iter((self,))
331+
def _infer(self: _T, context: Optional[InferenceContext] = None) -> Iterator[_T]:
332+
yield self

0 commit comments

Comments
 (0)