Skip to content

Commit

Permalink
Filter to just last declared function
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Feb 25, 2024
1 parent 4113a8f commit 5a86f41
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 9 additions & 0 deletions astroid/nodes/scoped_nodes/scoped_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2514,6 +2514,15 @@ def igetattr(
for attr in attributes
if attr.parent and attr.parent.scope() == first_scope
]
functions = [attr for attr in attributes if isinstance(attr, FunctionDef)]
if functions:
# Prefer only the last function, unless a property is involved.
last_function = functions[-1]
attributes = [
a
for a in attributes
if a not in functions or a is last_function or bases._is_property(a)
]

for inferred in bases._infer_stmts(attributes, context, frame=self):
# yield Uninferable object instead of descriptors when necessary
Expand Down
5 changes: 2 additions & 3 deletions tests/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -4349,9 +4349,8 @@ def foo(self):
"""
)
inferred = list(node.infer())
assert len(inferred) == 2
assert isinstance(inferred[0], nodes.Const)
assert isinstance(inferred[1], Generator)
assert len(inferred) == 1
assert isinstance(inferred[0], Generator)

def test_delayed_attributes_without_slots(self) -> None:
ast_node = extract_node(
Expand Down

0 comments on commit 5a86f41

Please sign in to comment.