Skip to content

Commit

Permalink
Fix a crash involving properties within try ... except blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielNoord committed Jul 8, 2022
1 parent 3ab9af6 commit 6fec464
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ Release date: TBA

Closes PyCQA/pylint#7092

* Fix a crash involving properties within ``try ... except`` blocks.

Closes PyCQA/pylint#6592

* Prevent creating ``Instance`` objects that proxy other ``Instance``s when there is
ambiguity (or user error) in calling ``__new__(cls)``.

Expand Down
3 changes: 3 additions & 0 deletions astroid/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,9 @@ def infer_functiondef(
property_already_in_parent_locals = self.name in parent_frame.locals and any(
isinstance(val, objects.Property) for val in parent_frame.locals[self.name]
)
# We also don't want to pass parent if the definition is within a Try node
if isinstance(self.parent, (nodes.TryExcept, nodes.TryFinally)):
property_already_in_parent_locals = True

prop_func = objects.Property(
function=self,
Expand Down
24 changes: 24 additions & 0 deletions tests/unittest_scoped_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2435,6 +2435,30 @@ class Derived(Parent):
assert isinstance(inferred, objects.Property)


def test_property_in_body_of_try() -> None:
"""Regression test for https://github.com/PyCQA/pylint/issues/6596."""
node: nodes.Return = builder._extract_single_node(
"""
def myfunc():
try:
@property
def myfunc():
return None
except TypeError:
pass
@myfunc.setter
def myfunc():
pass
return myfunc() #@
"""
)
next(node.value.infer())


def test_issue940_enums_as_a_real_world_usecase() -> None:
node = builder.extract_node(
"""
Expand Down

0 comments on commit 6fec464

Please sign in to comment.