Skip to content

Commit e14675c

Browse files
committed
Handle 3.7+ "else" branch removal...
As seen in _cmp() of python3.8/distutils/version.py with optimization -O2
1 parent 3449be0 commit e14675c

5 files changed

Lines changed: 23 additions & 1 deletion

File tree

test/add-test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
else:
2020
cfile = "bytecode_%s%s/%s" % (version, suffix, short) + "c"
2121
print("byte-compiling %s to %s" % (path, cfile))
22-
py_compile.compile(path, cfile)
22+
optimize = 2
23+
py_compile.compile(path, cfile, optimize=optimize)
2324
if isinstance(version, str) or version >= (2, 6, 0):
2425
os.system("../bin/uncompyle6 -a -T %s" % cfile)
254 Bytes
Binary file not shown.
262 Bytes
Binary file not shown.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# From python3.8/distutils/version.py with optimization -O2
2+
# The bug was that the other "else" constant propagated removed.
3+
4+
# NOTE: this program needs to be compile with optimization
5+
def _cmp (b, c):
6+
if b:
7+
if c:
8+
return 0
9+
else:
10+
return 1
11+
else:
12+
assert False, "never get here"

uncompyle6/parsers/parse37.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ def p_stmt(self, args):
9494
else_suitec ::= c_stmts
9595
else_suitec ::= returns
9696
97+
else_suite_opt ::= else_suite
98+
else_suite_opt ::= pass
99+
97100
stmt ::= classdef
98101
stmt ::= call_stmt
99102
@@ -635,6 +638,12 @@ def p_37conditionals(self, args):
635638
if_exp37 ::= expr expr jf_cfs expr COME_FROM
636639
jf_cfs ::= JUMP_FORWARD _come_froms
637640
ifelsestmt ::= testexpr c_stmts_opt jf_cfs else_suite opt_come_from_except
641+
642+
# This is probably more realistically an "ifstmt" (with a null else)
643+
# see _cmp() of python3.8/distutils/__pycache__/version.cpython-38.opt-1.pyc
644+
ifelsestmt ::= testexpr stmts jf_cfs else_suite_opt opt_come_from_except
645+
646+
638647
expr_pjit ::= expr POP_JUMP_IF_TRUE
639648
expr_jit ::= expr JUMP_IF_TRUE
640649
expr_jt ::= expr jmp_true

0 commit comments

Comments
 (0)