Skip to content

Commit a5f45f2

Browse files
committed
2.7: Detect "continue" inside except
Fixes issue rocky#38. This is a bit hacky. We need a more general "continue" detection.
1 parent d1ef0bf commit a5f45f2

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed
210 Bytes
Binary file not shown.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Issue #38 in Python 2.7
2+
# Problem is distinguishing 'continue' from 'jump_back'
3+
# in assembly instructions.
4+
5+
# Here, we hack looking for two jump backs
6+
# followed by the end of the except. This
7+
# is a big hack.
8+
9+
for a in [__name__]:
10+
try:len(a)
11+
except:continue

uncompyle6/scanners/scanner2.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import uncompyle6.scanner as scan
3333

3434
class Scanner2(scan.Scanner):
35-
def __init__(self, version, show_asm=None):
35+
def __init__(self, version, show_asm=None, is_pypy=False):
3636
scan.Scanner.__init__(self, version, show_asm)
3737
self.pop_jump_if = frozenset([self.opc.PJIF, self.opc.PJIT])
3838
self.jump_forward = frozenset([self.opc.JUMP_ABSOLUTE, self.opc.JUMP_FORWARD])
@@ -164,6 +164,18 @@ def unmangle(name):
164164
elif op in self.opc.hasjrel:
165165
pattr = repr(offset + 3 + oparg)
166166
elif op in self.opc.hasjabs:
167+
if self.version == 2.7 and op == self.opc.JUMP_ABSOLUTE:
168+
target = self.get_target(offset)
169+
# FIXME: this is a hack to catch stuff like:
170+
# for ...
171+
# try: ...
172+
# except: continue
173+
# the "continue" is not on a new line.
174+
n = len(tokens)
175+
if (n > 2 and
176+
tokens[-1].type == 'JUMP_BACK' and
177+
self.code[offset+3] == self.opc.END_FINALLY):
178+
tokens[-1].type = intern('CONTINUE')
167179
pattr = repr(oparg)
168180
elif op in self.opc.haslocal:
169181
pattr = varnames[oparg]

0 commit comments

Comments
 (0)