Skip to content

Commit

Permalink
Protect against infer_call_result failing with InferenceError i…
Browse files Browse the repository at this point in the history
…n `Super.getattr()` (#782)

``infer_call_result`` can raise InferenceError but we were not handling that when retrieving
objects from the Super instance.

Close pylint-dev/pylint#3529
  • Loading branch information
PCManticore committed May 1, 2020
1 parent e40ac59 commit 6aae915
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ Release Date: TBA

Close PyCQA/pylint#3549

* Protect against ``infer_call_result`` failing with `InferenceError` in `Super.getattr()`

Close PyCQA/pylint#3529


What's New in astroid 2.4.0?
============================
Expand Down
7 changes: 6 additions & 1 deletion astroid/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,12 @@ def igetattr(self, name, context=None):
yield inferred
elif isinstance(inferred, Property):
function = inferred.function
yield from function.infer_call_result(caller=self, context=context)
try:
yield from function.infer_call_result(
caller=self, context=context
)
except exceptions.InferenceError:
yield util.Uninferable
elif bases._is_property(inferred):
# TODO: support other descriptors as well.
try:
Expand Down
28 changes: 28 additions & 0 deletions tests/unittest_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -5818,5 +5818,33 @@ def __new__(cls, name, bases, dictionary):
assert dunder_new.implicit_parameters() == 0


def test_super_inference_of_abstract_property():
code = """
from abc import abstractmethod
class A:
@property
def test(self):
return "super"
class C:
@property
@abstractmethod
def test(self):
"abstract method"
class B(A, C):
@property
def test(self):
super() #@
"""
node = extract_node(code)
inferred = next(node.infer())
test = inferred.getattr("test")
assert len(test) == 2


if __name__ == "__main__":
unittest.main()

0 comments on commit 6aae915

Please sign in to comment.