summaryrefslogtreecommitdiff
path: root/rebuilder.py
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2014-03-04 09:29:46 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2014-03-04 09:29:46 +0200
commit230bf69325eef9c58a24db614c2a104638b6fbeb (patch)
tree5f531c755d247f2c805d1eaca367e679a7fc4f48 /rebuilder.py
parent2e0df240db0cf677b0821371af7c2dfc021452ab (diff)
downloadastroid-git-230bf69325eef9c58a24db614c2a104638b6fbeb.tar.gz
Drop yield_from API, add a new YieldFrom node instead.
--HG-- branch : yield_from
Diffstat (limited to 'rebuilder.py')
-rw-r--r--rebuilder.py20
1 files changed, 10 insertions, 10 deletions
diff --git a/rebuilder.py b/rebuilder.py
index 24ce8027..f6fae7b1 100644
--- a/rebuilder.py
+++ b/rebuilder.py
@@ -122,6 +122,14 @@ def _infer_metaclass(node):
elif isinstance(node, Attribute):
return node.attr
+def _create_yield_node(node, parent, rebuilder, factory):
+ newnode = factory()
+ _lineno_parent(node, newnode, parent)
+ if node.value is not None:
+ newnode.value = rebuilder.visit(node.value, newnode)
+ newnode.set_line_info(newnode.last_child())
+ return newnode
+
class TreeRebuilder(object):
"""Rebuilds the _ast tree to become an Astroid tree"""
@@ -837,13 +845,7 @@ class TreeRebuilder(object):
def visit_yield(self, node, parent):
"""visit a Yield node by returning a fresh instance of it"""
- newnode = new.Yield()
- _lineno_parent(node, newnode, parent)
- if node.value is not None:
- newnode.value = self.visit(node.value, newnode)
- newnode.set_line_info(newnode.last_child())
- return newnode
-
+ return _create_yield_node(node, parent, self, new.Yield)
class TreeRebuilder3k(TreeRebuilder):
"""extend and overwrite TreeRebuilder for python3k"""
@@ -954,9 +956,7 @@ class TreeRebuilder3k(TreeRebuilder):
return newnode
def visit_yieldfrom(self, node, parent):
- newnode = self.visit_yield(node, parent)
- newnode._from = True
- return newnode
+ return _create_yield_node(node, parent, self, new.YieldFrom)
def visit_class(self, node, parent):
newnode = super(TreeRebuilder3k, self).visit_class(node, parent)