summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2015-12-11 17:47:56 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2015-12-11 17:47:56 +0200
commit7f4ce0ece9eda79e7a098abbf4ed3c982450f9a1 (patch)
treef3e5e98268b663e25622d8e9ac8df0470fcf6d9a
parenta77489d20c536d3e4c92d637286fa9e7fb626813 (diff)
downloadastroid-git-7f4ce0ece9eda79e7a098abbf4ed3c982450f9a1.tar.gz
Ignore elements of sequences when converting them to AST with const_factory
const_factory is buggy in master, as well as the entire raw_building module, which means that at given points during rebuilding of ASTs from live objects, nodes are constructed with Python objects as elements, leading to various crashes with pylint and with astroid during certain inference paths. This is fixed in 2.0 though, where raw_building was completely rewritten, but bringing those changes back into master will need some more work to be done. Until this happens, we ignore the elements of sequences passed to const_factory, since they are not useful in anyway (and the code that uses them crashes anyway). This is just a temporary solution until we either merge master with 2.0 or backport raw_building changes from 2.0 to master.
-rw-r--r--astroid/node_classes.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/astroid/node_classes.py b/astroid/node_classes.py
index 175de6d7..8293fe45 100644
--- a/astroid/node_classes.py
+++ b/astroid/node_classes.py
@@ -1901,10 +1901,20 @@ def const_factory(value):
# node (another option being that const_factory shouldn't be called with something
# not in CONST_CLS)
assert not isinstance(value, NodeNG)
+
+ # Hack for ignoring elements of a sequence
+ # or a mapping, in order to avoid transforming
+ # each element to an AST. This is fixed in 2.0
+ # and this approach is a temporary hack.
+ if isinstance(value, (list, set, tuple, dict)):
+ elts = []
+ else:
+ elts = value
+
try:
initializer_cls = CONST_CLS[value.__class__]
initializer = _CONST_CLS_CONSTRUCTORS[initializer_cls]
- return initializer(initializer_cls, value)
+ return initializer(initializer_cls, elts)
except (KeyError, AttributeError) as exc:
node = EmptyNode()
node.object = value