summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2023-04-16 12:14:27 -0400
committerGitHub <noreply@github.com>2023-04-16 12:14:27 -0400
commit5869ee3ad40f4786be63294d9a0496af4ca1e886 (patch)
tree72d8b471da84ba0f47fbb962b7805ba4b3969699
parentee2d4bd07f4d2b9646ba8904ad6337d474c66fa6 (diff)
downloadastroid-git-5869ee3ad40f4786be63294d9a0496af4ca1e886.tar.gz
Port property-related workaround from `infer_functiondef` to `infer_property` (#2119)
-rw-r--r--ChangeLog4
-rw-r--r--astroid/brain/brain_builtin_inference.py3
-rw-r--r--tests/brain/test_builtin.py8
3 files changed, 14 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index f02a5851..0829e3c6 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 adea1c21..097404af 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/issues/1490
+ prop_func.parent = node
prop_func.postinit(
body=[],
args=inferred.args,
diff --git a/tests/brain/test_builtin.py b/tests/brain/test_builtin.py
index aa2924c6..c2a9de90 100644
--- a/tests/brain/test_builtin.py
+++ b/tests/brain/test_builtin.py
@@ -24,6 +24,14 @@ class BuiltinsTest(unittest.TestCase):
)
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"))