diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2015-11-23 13:44:11 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2015-11-23 13:44:11 +0200 |
commit | 02bdefc5b90d8a93436996f183e63e2a9f85706d (patch) | |
tree | a8ffaf01f0cbdbd5258fb20606852df39f04bde4 /astroid/tests/unittest_inference.py | |
parent | a36fefbd83d2cc021fce2793ffbfe25d2720a57e (diff) | |
download | astroid-02bdefc5b90d8a93436996f183e63e2a9f85706d.tar.gz |
Handle the cases when a List can contain Uninferable as its elements
This can happen for instance when the list contains objects which
weren't inferable in the first place. There were a bunch of places
affected by this bug: unpack_infer, the inference of list additions
and the handling of the namedtuple's fields.
Diffstat (limited to 'astroid/tests/unittest_inference.py')
-rw-r--r-- | astroid/tests/unittest_inference.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/astroid/tests/unittest_inference.py b/astroid/tests/unittest_inference.py index 98a4daf..853149a 100644 --- a/astroid/tests/unittest_inference.py +++ b/astroid/tests/unittest_inference.py @@ -1321,7 +1321,8 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): ast = parse(code, __name__) inferred = next(ast['Z'].infer()) self.assertIsInstance(inferred, nodes.List) - self.assertEqual(len(inferred.elts), 0) + self.assertEqual(len(inferred.elts), 1) + self.assertIs(inferred.elts[0], util.Uninferable) def test__new__(self): code = ''' @@ -2343,6 +2344,17 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): inferred = next(node.infer()) self.assertEqual(inferred.value, expected) + def test_binop_list_with_elts(self): + ast_node = test_utils.extract_node(''' + x = [A] * 1 + [1] + x + ''') + inferred = next(ast_node.infer()) + self.assertIsInstance(inferred, nodes.List) + self.assertEqual(len(inferred.elts), 2) + self.assertIsInstance(inferred.elts[0], nodes.Const) + self.assertIs(inferred.elts[1], util.Uninferable) + def test_binop_same_types(self): ast_nodes = test_utils.extract_node(''' class A(object): |