diff options
| -rw-r--r-- | as_string.py | 4 | ||||
| -rw-r--r-- | test/unittest_nodes.py | 10 |
2 files changed, 12 insertions, 2 deletions
diff --git a/as_string.py b/as_string.py index 76051111..d9b53dfe 100644 --- a/as_string.py +++ b/as_string.py @@ -173,7 +173,7 @@ class AsStringVisitor(ASTVisitor): def visit_dictcomp(self, node): """return an astng.DictComp node as string""" - return '[%s: %s %s]' % (node.key.accept(self), node.value.accept(self), + return '{%s: %s %s}' % (node.key.accept(self), node.value.accept(self), ' '.join([n.accept(self) for n in node.generators])) def visit_discard(self, node): @@ -333,7 +333,7 @@ class AsStringVisitor(ASTVisitor): def visit_setcomp(self, node): """return an astng.SetComp node as string""" - return '[%s %s]' % (node.elt.accept(self), ' '.join([n.accept(self) + return '{%s %s}' % (node.elt.accept(self), ' '.join([n.accept(self) for n in node.generators])) def visit_slice(self, node): diff --git a/test/unittest_nodes.py b/test/unittest_nodes.py index d4ae958e..d56a092c 100644 --- a/test/unittest_nodes.py +++ b/test/unittest_nodes.py @@ -234,6 +234,16 @@ class ImportNodeTC(testlib.TestCase): data = open(join(DATA, 'module2.py')).read() self.assertMultiLineEqual(as_string(MODULE2), data) + def test_2_7_as_string(self): + """check as_string for python syntax >= 2.7""" + if sys.version_info < (2, 7): + self.skipTest("test python >= 2.7 specific") + code = '''one_two = {1, 2} +b = {v: k for (k, v) in enumerate('string')} +cdd = {k for k in b}\n\n''' + ast = abuilder.string_build(code) + self.assertMultiLineEqual(as_string(ast), code) + class CmpNodeTC(testlib.TestCase): def test_as_string(self): |
