|
10 | 10 | import collections
|
11 | 11 | import collections.abc
|
12 | 12 | from collections.abc import Sequence
|
13 |
| -from typing import TYPE_CHECKING, Any |
| 13 | +from typing import Any |
14 | 14 |
|
15 |
| -from astroid import decorators |
| 15 | +from astroid import decorators, nodes |
16 | 16 | from astroid.const import PY310_PLUS
|
17 | 17 | from astroid.context import (
|
18 | 18 | CallContext,
|
|
33 | 33 | helpers = lazy_import("helpers")
|
34 | 34 | manager = lazy_import("manager")
|
35 | 35 |
|
36 |
| -if TYPE_CHECKING: |
37 |
| - from astroid import nodes |
38 |
| - |
39 | 36 |
|
40 | 37 | # TODO: check if needs special treatment
|
41 | 38 | BOOL_SPECIAL_METHOD = "__bool__"
|
@@ -271,10 +268,20 @@ def _wrap_attr(self, attrs, context=None):
|
271 | 268 | else:
|
272 | 269 | yield attr
|
273 | 270 |
|
274 |
| - def infer_call_result(self, caller, context=None): |
| 271 | + def infer_call_result( |
| 272 | + self, caller: nodes.Call | Proxy, context: InferenceContext | None = None |
| 273 | + ): |
275 | 274 | """infer what a class instance is returning when called"""
|
276 | 275 | context = bind_context_to_node(context, self)
|
277 | 276 | inferred = False
|
| 277 | + |
| 278 | + # If the call is an attribute on the instance, we infer the attribute itself |
| 279 | + if isinstance(caller, nodes.Call) and isinstance(caller.func, nodes.Attribute): |
| 280 | + for res in self.igetattr(caller.func.attrname, context): |
| 281 | + inferred = True |
| 282 | + yield res |
| 283 | + |
| 284 | + # Otherwise we infer the call to the __call__ dunder normally |
278 | 285 | for node in self._proxied.igetattr("__call__", context):
|
279 | 286 | if node is Uninferable or not node.callable():
|
280 | 287 | continue
|
@@ -418,9 +425,6 @@ def _infer_builtin_new(
|
418 | 425 | ) -> collections.abc.Generator[
|
419 | 426 | nodes.Const | Instance | type[Uninferable], None, None
|
420 | 427 | ]:
|
421 |
| - # pylint: disable-next=import-outside-toplevel; circular import |
422 |
| - from astroid import nodes |
423 |
| - |
424 | 428 | if not caller.args:
|
425 | 429 | return
|
426 | 430 | # Attempt to create a constant
|
|
0 commit comments