diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2014-03-08 10:08:35 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2014-03-08 10:08:35 +0200 |
commit | ed82d0d515da88a8d0b659ac30aec9d245a077d7 (patch) | |
tree | 36c1b55579b858151c67f5d8eb962d2fdecf21e9 /rebuilder.py | |
parent | 39a761f8b8ea3fb5213c2db047eef2726643b8ee (diff) | |
parent | d5cbe0db9a95798d61eb12d501fc39b8a95afa90 (diff) | |
download | astroid-git-ed82d0d515da88a8d0b659ac30aec9d245a077d7.tar.gz |
Merged in PCManticore/astroid/yield_from (pull request #23)
Add yield_from property for Yield nodes.
Diffstat (limited to 'rebuilder.py')
-rw-r--r-- | rebuilder.py | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/rebuilder.py b/rebuilder.py index b9a9adbb..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,7 +956,7 @@ class TreeRebuilder3k(TreeRebuilder): return newnode def visit_yieldfrom(self, node, parent): - return self.visit_yield(node, parent) + return _create_yield_node(node, parent, self, new.YieldFrom) def visit_class(self, node, parent): newnode = super(TreeRebuilder3k, self).visit_class(node, parent) |