From 58212bd459269da1b9cbf20ff23c3738f4d3dc3d Mon Sep 17 00:00:00 2001 From: Claudiu Popa Date: Fri, 1 Jan 2021 11:53:34 +0100 Subject: Fix a crash in inference caused by `Uninferable` container elements Close #866 --- tests/unittest_inference.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests') diff --git a/tests/unittest_inference.py b/tests/unittest_inference.py index e9e32fd6..cfc05791 100644 --- a/tests/unittest_inference.py +++ b/tests/unittest_inference.py @@ -5884,5 +5884,19 @@ def test_infer_generated_setter(): assert list(inferred.nodes_of_class(nodes.Const)) == [] +def test_infer_list_of_uninferables_does_not_crash(): + code = """ + x = [A] * 1 + f = [x, [A] * 2] + x = list(f) + [] # List[Uninferable] + tuple(x[0]) + """ + node = extract_node(code) + inferred = next(node.infer()) + assert isinstance(inferred, nodes.Tuple) + # Would not be able to infer the first element. + assert not inferred.elts + + if __name__ == "__main__": unittest.main() -- cgit v1.2.1