diff --git a/astroid/brain/brain_builtin_inference.py b/astroid/brain/brain_builtin_inference.py index 476620bd81..c60510d0b9 100644 --- a/astroid/brain/brain_builtin_inference.py +++ b/astroid/brain/brain_builtin_inference.py @@ -645,12 +645,15 @@ def infer_property( prop_func = objects.Property( function=inferred, - name=inferred.name, + name="", lineno=node.lineno, col_offset=node.col_offset, + # ↓ semantically, the definition of the class of property isn't within + # node.frame. It's somewhere in the builtins module, but we are special + # casing it for each "property()" call, so we are making up the + # definition on the spot, ad-hoc. + parent=AstroidManager().adhoc_module, ) - # 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 cf413f16cd..6c49a80042 100644 --- a/tests/brain/test_builtin.py +++ b/tests/brain/test_builtin.py @@ -14,7 +14,7 @@ class BuiltinsTest(unittest.TestCase): def test_infer_property(self): - class_with_property = _extract_single_node( + property_assign = _extract_single_node( """ class Something: def getter(): @@ -22,14 +22,15 @@ def getter(): asd = property(getter) #@ """ ) - inferred_property = next(iter(class_with_property.value.infer())) + inferred_property = next(iter(property_assign.value.infer())) self.assertTrue(isinstance(inferred_property, objects.Property)) - class_parent = inferred_property.parent.parent.parent + class_parent = property_assign.scope() self.assertIsInstance(class_parent, nodes.ClassDef) self.assertFalse( any( - isinstance(getter, objects.Property) - for getter in class_parent.locals["getter"] + isinstance(def_, objects.Property) + for def_list in class_parent.locals.values() + for def_ in def_list ) ) self.assertTrue(hasattr(inferred_property, "args"))