diff --git a/astroid/nodes/node_classes.py b/astroid/nodes/node_classes.py index 0538d4d169..ca2d217c95 100644 --- a/astroid/nodes/node_classes.py +++ b/astroid/nodes/node_classes.py @@ -16,6 +16,7 @@ Callable, ClassVar, Generator, + Iterator, Optional, Type, TypeVar, @@ -4876,7 +4877,9 @@ def __init__( parent=self.original.parent, ) - def infer(self, context=None, **kwargs): + def _infer( + self, context: Optional[InferenceContext] = None + ) -> Iterator[Union[NodeNG, Type[util.Uninferable]]]: yield self.value diff --git a/astroid/objects.py b/astroid/objects.py index 63166d5785..230c64d47f 100644 --- a/astroid/objects.py +++ b/astroid/objects.py @@ -12,8 +12,10 @@ """ import sys +from typing import Iterator, Optional, TypeVar from astroid import bases, decorators, util +from astroid.context import InferenceContext from astroid.exceptions import ( AttributeInferenceError, InferenceError, @@ -30,6 +32,8 @@ else: from astroid.decorators import cachedproperty as cached_property +_T = TypeVar("_T") + class FrozenSet(node_classes.BaseContainer): """class representing a FrozenSet composite node""" @@ -324,5 +328,5 @@ def pytype(self): def infer_call_result(self, caller=None, context=None): raise InferenceError("Properties are not callable") - def infer(self, context=None, **kwargs): - return iter((self,)) + def _infer(self: _T, context: Optional[InferenceContext] = None) -> Iterator[_T]: + yield self