Disable "continue" removal in pysource.py

"continue" could be the only statement and then removing it
might lead to a dangling "else".
This commit is contained in:
rocky
2017-06-08 04:35:06 -04:00
parent 7b2217fda4
commit e9588e56e2

View File

@@ -571,25 +571,32 @@ class SourceWalker(GenericASTTraversal, object):
node == AST('return_stmt', node == AST('return_stmt',
[AST('ret_expr', [NONE]), Token('RETURN_VALUE')])) [AST('ret_expr', [NONE]), Token('RETURN_VALUE')]))
def n_continue_stmt(self, node): ## The below doesn't work because continue may be the only thing inside an 'else'. For example
if self.version >= 3.0 and node[0] == 'CONTINUE': # for ...
t = node[0] # if ...
if not t.linestart: # else:
# Artificially-added "continue" statements derived from JUMP_ABSOLUTE # continue
# don't have line numbers associated with them. #
# If this is a CONTINUE is to the same target as a JUMP_ABSOLUTE following it, # def n_continue_stmt(self, node):
# then the "continue" can be suppressed. # if self.version >= 3.0 and node[0] == 'CONTINUE':
op, offset = t.op, t.offset # t = node[0]
next_offset = self.scanner.next_offset(op, offset) # if not t.linestart:
scanner = self.scanner # # Artificially-added "continue" statements derived from JUMP_ABSOLUTE
code = scanner.code # # don't have line numbers associated with them.
if next_offset < len(code): # # If this is a CONTINUE is to the same target as a JUMP_ABSOLUTE following it,
next_inst = code[next_offset] # # then the "continue" can be suppressed.
if (scanner.opc.opname[next_inst] == 'JUMP_ABSOLUTE' # op, offset = t.op, t.offset
and t.pattr == code[next_offset+1]): # next_offset = self.scanner.next_offset(op, offset)
# Suppress "continue" # scanner = self.scanner
self.prune() # code = scanner.code
self.default(node) # if next_offset < len(code):
# next_inst = code[next_offset]
# if (scanner.opc.opname[next_inst] == 'JUMP_ABSOLUTE'
# and t.pattr == code[next_offset+1]):
# # Suppress "continue"
# import pdb; pdb.set_trace()
# self.prune()
# self.default(node)
def n_return_stmt(self, node): def n_return_stmt(self, node):
if self.params['isLambda']: if self.params['isLambda']: