Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport maintenance/3.2.x] Fix RecursionError in infer_call_result() #2436

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ What's New in astroid 3.2.1?
============================
Release date: TBA

* Fix ``RecursionError`` in ``infer_call_result()`` for certain ``__call__`` methods.

Closes pylint-dev/pylint#9139


What's New in astroid 3.2.0?
Expand Down
5 changes: 5 additions & 0 deletions astroid/bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,11 @@ def infer_call_result(
for node in self._proxied.igetattr("__call__", context):
if isinstance(node, UninferableBase) or not node.callable():
continue
if isinstance(node, BaseInstance) and node._proxied is self._proxied:
inferred = True
yield node
# Prevent recursion.
continue
for res in node.infer_call_result(caller, context):
inferred = True
yield res
Expand Down
12 changes: 12 additions & 0 deletions tests/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -4090,6 +4090,18 @@ class C:
inferred = next(node.infer())
self.assertRaises(InferenceError, next, inferred.infer_call_result(node))

def test_infer_call_result_same_proxied_class(self) -> None:
node = extract_node(
"""
class A:
__call__ = A()
A() #@
"""
)
inferred = next(node.infer())
fully_evaluated_inference_results = list(inferred.infer_call_result(node))
assert fully_evaluated_inference_results[0].name == "A"

def test_infer_call_result_with_metaclass(self) -> None:
node = extract_node("def with_metaclass(meta, *bases): return 42")
inferred = next(node.infer_call_result(caller=node))
Expand Down
Loading