You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Back off pervasiveness of singleton reductions
This commit is contained in:
@@ -46,7 +46,10 @@ class PythonParser(GenericASTBuilder):
|
|||||||
self.collect = frozenset(nt_list)
|
self.collect = frozenset(nt_list)
|
||||||
|
|
||||||
# Reduce singleton reductions in these nonterminals:
|
# Reduce singleton reductions in these nonterminals:
|
||||||
self.singleton = frozenset(('str', 'joined_str', 'expr', 'store',
|
# FIXME: would love to do expr, sstmts, stmts and
|
||||||
|
# so on but that would require major changes to the
|
||||||
|
# semantic actions
|
||||||
|
self.singleton = frozenset(('str', 'joined_str', 'store',
|
||||||
'inplace_op'))
|
'inplace_op'))
|
||||||
|
|
||||||
def ast_first_offset(self, ast):
|
def ast_first_offset(self, ast):
|
||||||
|
@@ -661,8 +661,9 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
def is_return_none(self, node):
|
def is_return_none(self, node):
|
||||||
# Is there a better way?
|
# Is there a better way?
|
||||||
ret = (node[0] == 'ret_expr'
|
ret = (node[0] == 'ret_expr'
|
||||||
and node[0][0]== 'LOAD_CONST'
|
and node[0][0] == 'expr'
|
||||||
and node[0][0].pattr is None)
|
and node[0][0][0] == 'LOAD_CONST'
|
||||||
|
and node[0][0][0].pattr is None)
|
||||||
if self.version <= 2.6:
|
if self.version <= 2.6:
|
||||||
return ret
|
return ret
|
||||||
else:
|
else:
|
||||||
@@ -897,13 +898,11 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
"""
|
"""
|
||||||
self.write(self.indent, 'exec ')
|
self.write(self.indent, 'exec ')
|
||||||
self.preorder(node[0])
|
self.preorder(node[0])
|
||||||
|
if not node[1][0].isNone():
|
||||||
if not node[1].isNone():
|
|
||||||
sep = ' in '
|
sep = ' in '
|
||||||
for subnode in node[1]:
|
for subnode in node[1]:
|
||||||
self.write(sep); sep = ", "
|
self.write(sep); sep = ", "
|
||||||
self.preorder(subnode)
|
self.preorder(subnode)
|
||||||
|
|
||||||
self.println()
|
self.println()
|
||||||
self.prune() # stop recursing
|
self.prune() # stop recursing
|
||||||
|
|
||||||
@@ -1317,8 +1316,8 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
pass
|
pass
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
list_comp = ast[0]
|
ast = ast[0][0]
|
||||||
n = list_comp[iter_index]
|
n = ast[iter_index]
|
||||||
assert n == 'list_iter', n
|
assert n == 'list_iter', n
|
||||||
|
|
||||||
# FIXME: I'm not totally sure this is right.
|
# FIXME: I'm not totally sure this is right.
|
||||||
@@ -1407,9 +1406,8 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
if node == 'set_comp':
|
if node == 'set_comp':
|
||||||
ast = ast[0][0][0]
|
ast = ast[0][0][0]
|
||||||
else:
|
else:
|
||||||
ast = ast[0][0][0][0]
|
ast = ast[0][0][0][0][0]
|
||||||
|
|
||||||
assert ast == 'list_comp'
|
|
||||||
n = ast[1]
|
n = ast[1]
|
||||||
collection = node[-3]
|
collection = node[-3]
|
||||||
list_if = None
|
list_if = None
|
||||||
@@ -2328,10 +2326,10 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
# than fight (with the grammar to not emit "return None").
|
# than fight (with the grammar to not emit "return None").
|
||||||
if self.hide_internal:
|
if self.hide_internal:
|
||||||
if len(tokens) >= 2 and not noneInNames:
|
if len(tokens) >= 2 and not noneInNames:
|
||||||
if tokens[-1] in ('RETURN_VALUE', 'RETURN_VALUE_LAMBDA'):
|
if tokens[-1].kind in ('RETURN_VALUE', 'RETURN_VALUE_LAMBDA'):
|
||||||
# Python 3.4's classes can add a "return None" which is
|
# Python 3.4's classes can add a "return None" which is
|
||||||
# invalid syntax.
|
# invalid syntax.
|
||||||
if tokens[-2] == 'LOAD_CONST':
|
if tokens[-2].kind == 'LOAD_CONST':
|
||||||
if isTopLevel or tokens[-2].pattr is None:
|
if isTopLevel or tokens[-2].pattr is None:
|
||||||
del tokens[-2:]
|
del tokens[-2:]
|
||||||
else:
|
else:
|
||||||
|
Reference in New Issue
Block a user