summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2017-03-12 14:37:20 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2017-03-12 14:37:20 +0200
commit57a087f7555dfda286f3bd81c4712d126821306f (patch)
tree3087db9a5697fa33ce0d340a93aaf6c5682b1be2
parent7feb1df5c9580a54f12f480769626a4e16147ded (diff)
downloadastroid-git-57a087f7555dfda286f3bd81c4712d126821306f.tar.gz
Use nodes.Unknown instead of Uninferable for specifying unknown inference results
In the context of binop inference for lists and tuples, we were rebuilding a collection with the inferred elements. We were using Uninferable for specifying inference failures, but this leads to having non-AST nodes in collection's elts attribute, which should not happen. Instead, we replaced Uninferable with Unknown, meaning now we have an AST object.
-rw-r--r--astroid/nodes.py1
-rw-r--r--astroid/protocols.py7
-rw-r--r--astroid/tests/unittest_inference.py4
3 files changed, 8 insertions, 4 deletions
diff --git a/astroid/nodes.py b/astroid/nodes.py
index 861b0a66..2b207d02 100644
--- a/astroid/nodes.py
+++ b/astroid/nodes.py
@@ -42,6 +42,7 @@ from astroid.node_classes import (
Backquote, Discard, AssName, AssAttr, Getattr, CallFunc, From,
# Node not present in the builtin ast module.
DictUnpack,
+ Unknown,
)
from astroid.scoped_nodes import (
Module, GeneratorExp, Lambda, DictComp,
diff --git a/astroid/protocols.py b/astroid/protocols.py
index d1abdea0..605ae1ce 100644
--- a/astroid/protocols.py
+++ b/astroid/protocols.py
@@ -147,10 +147,13 @@ def _multiply_seq_by_int(self, opnode, other, context):
def _filter_uninferable_nodes(elts, context):
for elt in elts:
if elt is util.Uninferable:
- yield elt
+ yield nodes.Unknown()
else:
for inferred in elt.infer(context):
- yield inferred
+ if inferred is not util.Uninferable:
+ yield inferred
+ else:
+ yield nodes.Unknown()
@decorators.yes_if_nothing_inferred
diff --git a/astroid/tests/unittest_inference.py b/astroid/tests/unittest_inference.py
index a90803d6..9d4554db 100644
--- a/astroid/tests/unittest_inference.py
+++ b/astroid/tests/unittest_inference.py
@@ -1304,7 +1304,7 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase):
inferred = next(ast['Z'].infer())
self.assertIsInstance(inferred, nodes.List)
self.assertEqual(len(inferred.elts), 1)
- self.assertIs(inferred.elts[0], util.Uninferable)
+ self.assertIsInstance(inferred.elts[0], nodes.Unknown)
def test__new__(self):
code = '''
@@ -2479,7 +2479,7 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase):
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)
+ self.assertIsInstance(inferred.elts[1], nodes.Unknown)
def test_binop_same_types(self):
ast_nodes = extract_node('''