Skip to content

Commit ca9888a

Browse files
committed
Another 2.7 'continue' detection bug
1 parent 21377f3 commit ca9888a

File tree

4 files changed

+32
-12
lines changed

4 files changed

+32
-12
lines changed
73 Bytes
Binary file not shown.

test/simple_source/bug27+/05_for_try_except.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,10 @@
99
for a in [__name__]:
1010
try:len(a)
1111
except:continue
12+
13+
# The above has JUMP_ABSOLUTE in it.
14+
# This has JUMP_FORWARD instead.
15+
for a in [__name__]:
16+
try:len(a)
17+
except:continue
18+
y = 2

uncompyle6/scanners/scanner2.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,20 +161,14 @@ def unmangle(name):
161161
elif op in self.opc.hasname:
162162
pattr = names[oparg]
163163
elif op in self.opc.hasjrel:
164+
# use instead: hasattr(self, 'patch_continue'): ?
165+
if self.version == 2.7:
166+
self.patch_continue(tokens, offset, op)
164167
pattr = repr(offset + 3 + oparg)
165168
elif op in self.opc.hasjabs:
166-
if self.version == 2.7 and op == self.opc.JUMP_ABSOLUTE:
167-
target = self.get_target(offset)
168-
# FIXME: this is a hack to catch stuff like:
169-
# for ...
170-
# try: ...
171-
# except: continue
172-
# the "continue" is not on a new line.
173-
n = len(tokens)
174-
if (n > 2 and
175-
tokens[-1].type == 'JUMP_BACK' and
176-
self.code[offset+3] == self.opc.END_FINALLY):
177-
tokens[-1].type = intern('CONTINUE')
169+
# use instead: hasattr(self, 'patch_continue'): ?
170+
if self.version == 2.7:
171+
self.patch_continue(tokens, offset, op)
178172
pattr = repr(oparg)
179173
elif op in self.opc.haslocal:
180174
pattr = varnames[oparg]

uncompyle6/scanners/scanner27.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212

1313
from uncompyle6.scanners.scanner2 import Scanner2
1414

15+
from uncompyle6 import PYTHON3
16+
if PYTHON3:
17+
import sys
18+
intern = sys.intern
19+
1520
# bytecode verification, verify(), uses JUMP_OPs from here
1621
from xdis.opcodes import opcode_27
1722
JUMP_OPs = opcode_27.JUMP_OPs
@@ -76,6 +81,20 @@ def __init__(self, show_asm=False, is_pypy=False):
7681
self.opc.JUMP_IF_TRUE_OR_POP])
7782

7883
return
84+
85+
def patch_continue(self, tokens, offset, op):
86+
if op in (self.opc.JUMP_FORWARD, self.opc.JUMP_ABSOLUTE):
87+
# FIXME: this is a hack to catch stuff like:
88+
# for ...
89+
# try: ...
90+
# except: continue
91+
# the "continue" is not on a new line.
92+
n = len(tokens)
93+
if (n > 2 and
94+
tokens[-1].type == 'JUMP_BACK' and
95+
self.code[offset+3] == self.opc.END_FINALLY):
96+
tokens[-1].type = intern('CONTINUE')
97+
7998
pass
8099

81100
if __name__ == "__main__":

0 commit comments

Comments
 (0)