From 5c348936ebe076b8a7b9d33af3e4770e84df7b9b Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sat, 15 Apr 2023 16:51:02 -0400 Subject: [PATCH 1/3] Port property-related workaround from infer_functiondef to infer_property --- ChangeLog | 4 ++++ astroid/brain/brain_builtin_inference.py | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index f02a58516c..0829e3c613 100644 --- a/ChangeLog +++ b/ChangeLog @@ -57,6 +57,10 @@ Release date: TBA Closes pylint-dev/pylint#8544 +* ``infer_property()`` now observes the same property-specific workaround as ``infer_functiondef``. + + Refs #1490 + What's New in astroid 2.15.3? ============================= Release date: TBA diff --git a/astroid/brain/brain_builtin_inference.py b/astroid/brain/brain_builtin_inference.py index adea1c2144..22972ae843 100644 --- a/astroid/brain/brain_builtin_inference.py +++ b/astroid/brain/brain_builtin_inference.py @@ -562,9 +562,10 @@ def infer_property( function=inferred, name=inferred.name, lineno=node.lineno, - parent=node, col_offset=node.col_offset, ) + # Set parent outside __init__: https://github.com/pylint-dev/astroid#1490 + prop_func.parent = node prop_func.postinit( body=[], args=inferred.args, From 819e7a912121287bb16b34d8042aef24411fc8cb Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sat, 15 Apr 2023 16:53:17 -0400 Subject: [PATCH 2/3] Fix URL --- astroid/brain/brain_builtin_inference.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/astroid/brain/brain_builtin_inference.py b/astroid/brain/brain_builtin_inference.py index 22972ae843..097404afc6 100644 --- a/astroid/brain/brain_builtin_inference.py +++ b/astroid/brain/brain_builtin_inference.py @@ -564,7 +564,7 @@ def infer_property( lineno=node.lineno, col_offset=node.col_offset, ) - # Set parent outside __init__: https://github.com/pylint-dev/astroid#1490 + # Set parent outside __init__: https://github.com/pylint-dev/astroid/issues/1490 prop_func.parent = node prop_func.postinit( body=[], From 1623a8a9eef377c5749e81425ea6231cdf3e1570 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sat, 15 Apr 2023 21:44:27 -0400 Subject: [PATCH 3/3] Add test --- tests/brain/test_builtin.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/brain/test_builtin.py b/tests/brain/test_builtin.py index aa2924c69b..c2a9de9001 100644 --- a/tests/brain/test_builtin.py +++ b/tests/brain/test_builtin.py @@ -24,6 +24,14 @@ def getter(): ) inferred_property = list(class_with_property.value.infer())[0] self.assertTrue(isinstance(inferred_property, objects.Property)) + class_parent = inferred_property.parent.parent.parent + self.assertIsInstance(class_parent, nodes.ClassDef) + self.assertFalse( + any( + isinstance(getter, objects.Property) + for getter in class_parent.locals["getter"] + ) + ) self.assertTrue(hasattr(inferred_property, "args"))