Add UNARY convert; improve 2.1 imports

This commit is contained in:
rocky
2017-11-27 21:38:09 -05:00
parent 2ac8a0c0a6
commit 4b4fce01f6
4 changed files with 32 additions and 5 deletions

Binary file not shown.

View File

@@ -0,0 +1,2 @@
# Python 2's deprecated unary convert (akin to "repr()"
`abc`

View File

@@ -38,6 +38,7 @@ class PythonParser(GenericASTBuilder):
# Python < 3
'print_items',
# PyPy:
'imports_cont',
'kvlist_n']
self.collect = frozenset(nt_list)

View File

@@ -306,7 +306,17 @@ class SourceWalker(GenericASTTraversal, object):
TABLE_DIRECT.update({
'tryfinallystmt': ( '%|try:\n%+%c%-%|finally:\n%+%c%-\n\n', 1, 4 )
})
if version <= 2.1:
TABLE_DIRECT.update({
'importmultiple': ( '%c', 2 ),
'imports_cont': ( '%c', 2 ),
# FIXME: not quite right. We have indiividual imports
# when there is in fact one: "import a, b, ..."
'imports_cont': ( '%C%,', (1, 100, '\n') ),
})
pass
pass
pass
elif version >= 2.5:
########################
# Import style for 2.5+
@@ -980,6 +990,20 @@ class SourceWalker(GenericASTTraversal, object):
self.prune()
def n_import_as(self, node):
if self.version <= 2.1:
if len(node) == 2:
designator = node[1]
assert designator == 'designator'
if designator[0].pattr == node[0].pattr:
self.write("import %s\n" % node[0].pattr)
else:
self.write("import %s as %s\n" %
(node[0].pattr, designator[0].pattr))
pass
pass
self.prune() # stop recursing
store_node = node[-1][-1]
assert store_node.kind.startswith('STORE_')
iname = node[0].pattr # import name