Skip to content

Commit 5869ee3

Browse files
Port property-related workaround from infer_functiondef to infer_property (#2119)
1 parent ee2d4bd commit 5869ee3

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

ChangeLog

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ Release date: TBA
5757

5858
Closes pylint-dev/pylint#8544
5959

60+
* ``infer_property()`` now observes the same property-specific workaround as ``infer_functiondef``.
61+
62+
Refs #1490
63+
6064
What's New in astroid 2.15.3?
6165
=============================
6266
Release date: TBA

astroid/brain/brain_builtin_inference.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -562,9 +562,10 @@ def infer_property(
562562
function=inferred,
563563
name=inferred.name,
564564
lineno=node.lineno,
565-
parent=node,
566565
col_offset=node.col_offset,
567566
)
567+
# Set parent outside __init__: https://github.com/pylint-dev/astroid/issues/1490
568+
prop_func.parent = node
568569
prop_func.postinit(
569570
body=[],
570571
args=inferred.args,

tests/brain/test_builtin.py

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ def getter():
2424
)
2525
inferred_property = list(class_with_property.value.infer())[0]
2626
self.assertTrue(isinstance(inferred_property, objects.Property))
27+
class_parent = inferred_property.parent.parent.parent
28+
self.assertIsInstance(class_parent, nodes.ClassDef)
29+
self.assertFalse(
30+
any(
31+
isinstance(getter, objects.Property)
32+
for getter in class_parent.locals["getter"]
33+
)
34+
)
2735
self.assertTrue(hasattr(inferred_property, "args"))
2836

2937

0 commit comments

Comments
 (0)