From cb1d72427fcc9d889f1aca2902d714026a673c17 Mon Sep 17 00:00:00 2001 From: Claudiu Popa Date: Fri, 1 May 2020 09:01:57 +0200 Subject: [PATCH] Protect against ``infer_call_result`` failing with `InferenceError` in `Super.getattr()` ``infer_call_result`` can raise InferenceError but we were not handling that when retrieving objects from the Super instance. Close PyCQA/pylint#3529 --- ChangeLog | 4 ++++ astroid/objects.py | 7 ++++++- tests/unittest_inference.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index e5fd0d908..f83dd8728 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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? ============================ diff --git a/astroid/objects.py b/astroid/objects.py index 68d74aa2f..fb782e6d7 100644 --- a/astroid/objects.py +++ b/astroid/objects.py @@ -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: diff --git a/tests/unittest_inference.py b/tests/unittest_inference.py index e267f9702..cfbcd6f86 100644 --- a/tests/unittest_inference.py +++ b/tests/unittest_inference.py @@ -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()