Skip to content

Commit a2d8470

Browse files
Fix AssertionError when inferring a property consisting of a partial function. (#2458) (#2460)
Closes pylint-dev/pylint#9214 Thanks Martin Belanger for the report and Bryce Guinta for the test case. (cherry picked from commit 0f9dfa6) Co-authored-by: Jacob Walls <[email protected]>
1 parent 006b1ac commit a2d8470

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
@@ -13,6 +13,10 @@ What's New in astroid 3.2.3?
1313
============================
1414
Release date: TBA
1515

16+
* Fix ``AssertionError`` when inferring a property consisting of a partial function.
17+
18+
Closes pylint-dev/pylint#9214
19+
1620

1721

1822
What's New in astroid 3.2.2?

astroid/nodes/scoped_nodes/scoped_nodes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2539,6 +2539,10 @@ def igetattr(
25392539
elif isinstance(inferred, objects.Property):
25402540
function = inferred.function
25412541
if not class_context:
2542+
if not context.callcontext:
2543+
context.callcontext = CallContext(
2544+
args=function.args.arguments, callee=function
2545+
)
25422546
# Through an instance so we can solve the property
25432547
yield from function.infer_call_result(
25442548
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)