summaryrefslogtreecommitdiff
path: root/as_string.py
diff options
context:
space:
mode:
Diffstat (limited to 'as_string.py')
-rw-r--r--as_string.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/as_string.py b/as_string.py
index d9b53dfe..3eeda096 100644
--- a/as_string.py
+++ b/as_string.py
@@ -34,7 +34,6 @@ It will probably not work on compiler.ast or _ast trees.
"""
import sys
-from logilab.astng.utils import ASTVisitor
INDENT = ' ' # 4 spaces ; keep indentation variable
@@ -50,7 +49,7 @@ def _import_string(names):
return ', '.join(_names)
-class AsStringVisitor(ASTVisitor):
+class AsStringVisitor(object):
"""Visitor to render an ASTNG node as string """
def __call__(self, node):
@@ -179,7 +178,11 @@ class AsStringVisitor(ASTVisitor):
def visit_discard(self, node):
"""return an astng.Discard node as string"""
return node.value.accept(self)
-
+
+ def visit_emptynode(self, node):
+ """dummy method for visiting an Empty node"""
+ return ''
+
def visit_excepthandler(self, node):
if node.type:
if node.name:
@@ -225,8 +228,8 @@ class AsStringVisitor(ASTVisitor):
def visit_from(self, node):
"""return an astng.From node as string"""
- # XXX level
- return 'from %s import %s' % (node.modname, _import_string(node.names))
+ return 'from %s import %s' % ('.' * (node.level or 0) + node.modname,
+ _import_string(node.names))
def visit_function(self, node):
"""return an astng.Function node as string"""
@@ -392,7 +395,8 @@ class AsStringVisitor(ASTVisitor):
def visit_yield(self, node):
"""yield an ast.Yield node as string"""
- return 'yield %s' % node.value.accept(self)
+ yi_val = node.value and (" " + node.value.accept(self)) or ""
+ return 'yield' + yi_val
class AsStringVisitor3k(AsStringVisitor):