Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port property-related workaround from infer_functiondef to infer_property #2119

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion astroid/brain/brain_builtin_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions tests/brain/test_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))


Expand Down