Skip to content

Commit

Permalink
Fix RecursionError in infer_call_result() (#2432) (#2436)
Browse files Browse the repository at this point in the history
(cherry picked from commit d1c37a9)

Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
  • Loading branch information
github-actions[bot] and jacobtylerwalls committed May 14, 2024
1 parent 7d4d805 commit a7ff092
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
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

0 comments on commit a7ff092

Please sign in to comment.