Skip to content

Commit 3047277

Browse files
authored
Fix builtin inference on property not including function arguments
2 parents e005459 + 3db9745 commit 3047277

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ What's New in astroid 2.10.0?
66
=============================
77
Release date: TBA
88

9+
* Fixed builtin inferenence on `property` calls not calling the `postinit` of the new node, which
10+
resulted in instance arguments missing on these nodes.
911

1012
What's New in astroid 2.9.4?
1113
============================

astroid/brain/brain_builtin_inference.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,14 +566,16 @@ def infer_property(node, context=None):
566566
if not isinstance(inferred, (nodes.FunctionDef, nodes.Lambda)):
567567
raise UseInferenceDefault
568568

569-
return objects.Property(
569+
prop_func = objects.Property(
570570
function=inferred,
571571
name=inferred.name,
572572
doc=getattr(inferred, "doc", None),
573573
lineno=node.lineno,
574574
parent=node,
575575
col_offset=node.col_offset,
576576
)
577+
prop_func.postinit(body=[], args=inferred.args)
578+
return prop_func
577579

578580

579581
def infer_bool(node, context=None):

tests/unittest_brain_builtin.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
2+
# For details: https://github.com/PyCQA/astroid/blob/main/LICENSE
3+
"""Unit Tests for the builtins brain module."""
4+
5+
import unittest
6+
7+
from astroid import extract_node, objects
8+
9+
10+
class BuiltinsTest(unittest.TestCase):
11+
def test_infer_property(self):
12+
class_with_property = extract_node(
13+
"""
14+
class Something:
15+
def getter():
16+
return 5
17+
asd = property(getter) #@
18+
"""
19+
)
20+
inferred_property = list(class_with_property.value.infer())[0]
21+
self.assertTrue(isinstance(inferred_property, objects.Property))
22+
self.assertTrue(hasattr(inferred_property, "args"))

0 commit comments

Comments
 (0)