Skip to content

Commit c77a574

Browse files
authored
Protect against infer_call_result failing with InferenceError in 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
1 parent a3d86bd commit c77a574

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ Release Date: TBA
2323

2424
Close PyCQA/pylint#3549
2525

26+
* Protect against ``infer_call_result`` failing with `InferenceError` in `Super.getattr()`
27+
28+
Close PyCQA/pylint#3529
29+
2630

2731
What's New in astroid 2.4.0?
2832
============================

astroid/objects.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,12 @@ def igetattr(self, name, context=None):
187187
yield inferred
188188
elif isinstance(inferred, Property):
189189
function = inferred.function
190-
yield from function.infer_call_result(caller=self, context=context)
190+
try:
191+
yield from function.infer_call_result(
192+
caller=self, context=context
193+
)
194+
except exceptions.InferenceError:
195+
yield util.Uninferable
191196
elif bases._is_property(inferred):
192197
# TODO: support other descriptors as well.
193198
try:

tests/unittest_inference.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5818,5 +5818,33 @@ def __new__(cls, name, bases, dictionary):
58185818
assert dunder_new.implicit_parameters() == 0
58195819

58205820

5821+
def test_super_inference_of_abstract_property():
5822+
code = """
5823+
from abc import abstractmethod
5824+
5825+
class A:
5826+
@property
5827+
def test(self):
5828+
return "super"
5829+
5830+
class C:
5831+
@property
5832+
@abstractmethod
5833+
def test(self):
5834+
"abstract method"
5835+
5836+
class B(A, C):
5837+
5838+
@property
5839+
def test(self):
5840+
super() #@
5841+
5842+
"""
5843+
node = extract_node(code)
5844+
inferred = next(node.infer())
5845+
test = inferred.getattr("test")
5846+
assert len(test) == 2
5847+
5848+
58215849
if __name__ == "__main__":
58225850
unittest.main()

0 commit comments

Comments
 (0)