Skip to content

Commit

Permalink
Fix AssertionError when inferring a property consisting of a partial …
Browse files Browse the repository at this point in the history
…function. (#2458)

Closes pylint-dev/pylint#9214

Thanks Martin Belanger for the report and
Bryce Guinta for the test case.
  • Loading branch information
jacobtylerwalls authored Jul 8, 2024
1 parent fb6f5bc commit 0f9dfa6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ What's New in astroid 3.2.3?
============================
Release date: TBA

* Fix ``AssertionError`` when inferring a property consisting of a partial function.

Closes pylint-dev/pylint#9214


What's New in astroid 3.2.2?
============================
Expand Down
4 changes: 4 additions & 0 deletions astroid/nodes/scoped_nodes/scoped_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2518,6 +2518,10 @@ def igetattr(
elif isinstance(inferred, objects.Property):
function = inferred.function
if not class_context:
if not context.callcontext:
context.callcontext = CallContext(
args=function.args.arguments, callee=function
)
# Through an instance so we can solve the property
yield from function.infer_call_result(
caller=self, context=context
Expand Down
19 changes: 19 additions & 0 deletions tests/test_regrtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,22 @@ def test_recursion_during_inference(mocked) -> None:
with pytest.raises(InferenceError) as error:
next(node.infer())
assert error.value.message.startswith("RecursionError raised")


def test_regression_missing_callcontext() -> None:
node: nodes.Attribute = _extract_single_node(
textwrap.dedent(
"""
import functools
class MockClass:
def _get_option(self, option):
return "mystr"
enabled = property(functools.partial(_get_option, option='myopt'))
MockClass().enabled
"""
)
)
assert node.inferred()[0].value == "mystr"

0 comments on commit 0f9dfa6

Please sign in to comment.