X Tutup
Skip to content

Commit f6f3ad3

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 f6f3ad3

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
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: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,21 @@
2222

2323
from __future__ import print_function
2424

25-
import inspect
25+
import inspect, sys
2626
from collections import namedtuple
2727
from array import array
2828

2929
from xdis.code import iscode
3030
from xdis.bytecode import findlinestarts
3131

3232
import uncompyle6.scanner as scan
33+
from uncompyle6 import PYTHON3
34+
35+
if PYTHON3:
36+
intern = sys.intern
3337

3438
class Scanner2(scan.Scanner):
35-
def __init__(self, version, show_asm=None):
39+
def __init__(self, version, show_asm=None, is_pypy=False):
3640
scan.Scanner.__init__(self, version, show_asm)
3741
self.pop_jump_if = frozenset([self.opc.PJIF, self.opc.PJIT])
3842
self.jump_forward = frozenset([self.opc.JUMP_ABSOLUTE, self.opc.JUMP_FORWARD])
@@ -164,6 +168,18 @@ def unmangle(name):
164168
elif op in self.opc.hasjrel:
165169
pattr = repr(offset + 3 + oparg)
166170
elif op in self.opc.hasjabs:
171+
if self.version == 2.7 and op == self.opc.JUMP_ABSOLUTE:
172+
target = self.get_target(offset)
173+
# FIXME: this is a hack to catch stuff like:
174+
# for ...
175+
# try: ...
176+
# except: continue
177+
# the "continue" is not on a new line.
178+
n = len(tokens)
179+
if (n > 2 and
180+
tokens[-1].type == 'JUMP_BACK' and
181+
self.code[offset+3] == self.opc.END_FINALLY):
182+
tokens[-1].type = intern('CONTINUE')
167183
pattr = repr(oparg)
168184
elif op in self.opc.haslocal:
169185
pattr = varnames[oparg]

0 commit comments

Comments
 (0)
X Tutup