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()`

``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 a3d86bd commit cb1d724
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ChangeLog
Expand Up @@ -23,6 +23,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
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
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 cb1d724

Please sign in to comment.