diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2015-11-29 22:11:22 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2015-11-29 22:11:22 +0200 |
commit | c486ba77ea44edc119e723286e26158a65436037 (patch) | |
tree | 508699456ce844e2707ccd15a850ac3c04f2520e /astroid/tests/unittest_nodes.py | |
parent | 65cf5619390921d2b08fcd1899b54197bafeefb8 (diff) | |
download | astroid-c486ba77ea44edc119e723286e26158a65436037.tar.gz |
Add support for handling Uninferable nodes when calling as_string
Some object, for instance List or Tuple can have, after inference,
Uninferable as their elements, happening when their components
weren't couldn't be inferred properly. This means that as_string
needs to cope with expecting Uninferable nodes part of the other
nodes coming for a string transformation. The patch adds a visit
method in AsString and ``accept`` on Yes / Uninferable nodes.
Closes issue #270.
Diffstat (limited to 'astroid/tests/unittest_nodes.py')
-rw-r--r-- | astroid/tests/unittest_nodes.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/astroid/tests/unittest_nodes.py b/astroid/tests/unittest_nodes.py index 3677bfb..e2e8338 100644 --- a/astroid/tests/unittest_nodes.py +++ b/astroid/tests/unittest_nodes.py @@ -62,6 +62,16 @@ class AsStringTest(resources.SysPathSetup, unittest.TestCase): node = parse(code) self.assertEqual(node.as_string().strip(), code.strip()) + def test_as_string_for_list_containing_uninferable(self): + node = test_utils.extract_node(''' + def foo(): + bar = [arg] * 1 + ''') + binop = node.body[0].value + inferred = next(binop.infer()) + self.assertEqual(inferred.as_string(), '[Uninferable]') + self.assertEqual(binop.as_string(), '([arg]) * (1)') + def test_frozenset_as_string(self): nodes = test_utils.extract_node(''' frozenset((1, 2, 3)) #@ |