Skip to content

Commit 39305fd

Browse files
committed
Fix typing of _infer to allow a return value in the Generator
1 parent 5f01da9 commit 39305fd

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

astroid/bases.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import collections
1111
import collections.abc
1212
from collections.abc import Sequence
13-
from typing import TYPE_CHECKING, Any, TypeVar
13+
from typing import TYPE_CHECKING, Any
1414

1515
from astroid import decorators
1616
from astroid.const import PY310_PLUS
@@ -26,7 +26,7 @@
2626
InferenceError,
2727
NameInferenceError,
2828
)
29-
from astroid.typing import InferenceResult
29+
from astroid.typing import InferenceErrorInfo, InferenceResult
3030
from astroid.util import Uninferable, lazy_descriptor, lazy_import
3131

3232
objectmodel = lazy_import("interpreter.objectmodel")
@@ -36,7 +36,6 @@
3636
if TYPE_CHECKING:
3737
from astroid import nodes
3838

39-
_ProxyT = TypeVar("_ProxyT", bound="Proxy")
4039

4140
# TODO: check if needs special treatment
4241
BOOL_SPECIAL_METHOD = "__bool__"
@@ -119,9 +118,9 @@ def __getattr__(self, name):
119118
return self.__dict__[name]
120119
return getattr(self._proxied, name)
121120

122-
def infer(
123-
self: _ProxyT, context: InferenceContext | None = None, **kwargs: Any
124-
) -> collections.abc.Generator[_ProxyT, None, None]:
121+
def infer( # type: ignore[return]
122+
self, context: InferenceContext | None = None, **kwargs: Any
123+
) -> collections.abc.Generator[InferenceResult, None, InferenceErrorInfo | None]:
125124
yield self
126125

127126

astroid/nodes/node_ng.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from astroid.nodes.as_string import AsStringVisitor
3535
from astroid.nodes.const import OP_PRECEDENCE
3636
from astroid.nodes.utils import Position
37-
from astroid.typing import InferenceResult, InferFn
37+
from astroid.typing import InferenceErrorInfo, InferenceResult, InferFn
3838

3939
if TYPE_CHECKING:
4040
from astroid import nodes
@@ -593,7 +593,7 @@ def _infer_name(self, frame, name):
593593

594594
def _infer(
595595
self, context: InferenceContext | None = None, **kwargs: Any
596-
) -> Generator[InferenceResult, None, None]:
596+
) -> Generator[InferenceResult, None, InferenceErrorInfo | None]:
597597
"""we don't know how to resolve a statement by default"""
598598
# this method is overridden by most concrete classes
599599
raise InferenceError(

astroid/objects.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from __future__ import annotations
1515

1616
import sys
17-
from collections.abc import Iterator
17+
from collections.abc import Generator
1818
from typing import Any, TypeVar
1919

2020
from astroid import bases, decorators, util
@@ -333,5 +333,5 @@ def infer_call_result(self, caller=None, context=None):
333333

334334
def _infer(
335335
self: _T, context: InferenceContext | None = None, **kwargs: Any
336-
) -> Iterator[_T]:
336+
) -> Generator[_T, None, None]:
337337
yield self

0 commit comments

Comments
 (0)