Skip to content

Commit 0f9dfa6

Browse files
Fix AssertionError when inferring a property consisting of a partial function. (#2458)
Closes pylint-dev/pylint#9214 Thanks Martin Belanger for the report and Bryce Guinta for the test case.
1 parent fb6f5bc commit 0f9dfa6

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ What's New in astroid 3.2.3?
1616
============================
1717
Release date: TBA
1818

19+
* Fix ``AssertionError`` when inferring a property consisting of a partial function.
20+
21+
Closes pylint-dev/pylint#9214
22+
1923

2024
What's New in astroid 3.2.2?
2125
============================

astroid/nodes/scoped_nodes/scoped_nodes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2518,6 +2518,10 @@ def igetattr(
25182518
elif isinstance(inferred, objects.Property):
25192519
function = inferred.function
25202520
if not class_context:
2521+
if not context.callcontext:
2522+
context.callcontext = CallContext(
2523+
args=function.args.arguments, callee=function
2524+
)
25212525
# Through an instance so we can solve the property
25222526
yield from function.infer_call_result(
25232527
caller=self, context=context

tests/test_regrtest.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,3 +477,22 @@ def test_recursion_during_inference(mocked) -> None:
477477
with pytest.raises(InferenceError) as error:
478478
next(node.infer())
479479
assert error.value.message.startswith("RecursionError raised")
480+
481+
482+
def test_regression_missing_callcontext() -> None:
483+
node: nodes.Attribute = _extract_single_node(
484+
textwrap.dedent(
485+
"""
486+
import functools
487+
488+
class MockClass:
489+
def _get_option(self, option):
490+
return "mystr"
491+
492+
enabled = property(functools.partial(_get_option, option='myopt'))
493+
494+
MockClass().enabled
495+
"""
496+
)
497+
)
498+
assert node.inferred()[0].value == "mystr"

0 commit comments

Comments
 (0)