Skip to content

Commit

Permalink
Define _infer instead of infer on subclasses of NodeNG
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielNoord committed May 5, 2022
1 parent f125fa7 commit 9aabf76
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion astroid/nodes/node_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Callable,
ClassVar,
Generator,
Iterator,
Optional,
Type,
TypeVar,
Expand Down Expand Up @@ -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


Expand Down
8 changes: 6 additions & 2 deletions astroid/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"""
Expand Down Expand Up @@ -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

0 comments on commit 9aabf76

Please sign in to comment.