You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Merge pull request #202 from rocky/assert-fix
Better handling of AssertError. I expect fewer asserts to be recognized in favor of if AssertError. Also, this fixes one thing but breaks 04_assert_continue.pyc
This commit is contained in:
10
test/simple_source/bug24/03_iftrue.py
Normal file
10
test/simple_source/bug24/03_iftrue.py
Normal file
@@ -0,0 +1,10 @@
|
||||
# Python 2.4 (and before?) bug in handling unconditional "else if true"
|
||||
# Doesn't occur in Python > 2.4
|
||||
# From Issue #187
|
||||
def unconditional_if_true_24(foo):
|
||||
if not foo:
|
||||
pass
|
||||
elif 1:
|
||||
pass
|
||||
else:
|
||||
return None
|
22
test/simple_source/bug27+/06_raise.py
Normal file
22
test/simple_source/bug27+/06_raise.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# Bug in Python 2.7 is code creating a (useless) JUMP_ABSOLUTE to the instruction right after
|
||||
# the "raise" which causes the
|
||||
|
||||
# RUNNABLE!
|
||||
def testit(a, b):
|
||||
if a:
|
||||
if not b:
|
||||
raise AssertionError("test JUMP_ABSOLUTE to next instruction")
|
||||
|
||||
def testit2(a, b):
|
||||
if a:
|
||||
if not b:
|
||||
raise AssertionError("test with dead code after raise")
|
||||
x = 10
|
||||
|
||||
testit(False, True)
|
||||
testit(False, False)
|
||||
testit(True, True)
|
||||
|
||||
testit2(False, True)
|
||||
testit2(False, False)
|
||||
testit2(True, True)
|
@@ -4,6 +4,7 @@
|
||||
# try. In 3.x we not distinguising this jump out of the loop with a jump to the
|
||||
# end of the "try".
|
||||
|
||||
# RUNNABLE!
|
||||
def testit(stmts):
|
||||
|
||||
# Bug was confusing When the except jumps back to the beginning of the block
|
||||
|
8
test/simple_source/bug36/03_if_try.py
Normal file
8
test/simple_source/bug36/03_if_try.py
Normal file
@@ -0,0 +1,8 @@
|
||||
# The bug in python 3.6+ was in parsing that we
|
||||
# add END_IF_THEN and using that inside "return results"
|
||||
def whcms_license_info(md5hash, datahash, results):
|
||||
if md5hash == datahash:
|
||||
try:
|
||||
return md5hash
|
||||
except:
|
||||
return results
|
@@ -533,14 +533,11 @@ class Python2Parser(PythonParser):
|
||||
# Dead code testing...
|
||||
# if lhs == 'while1elsestmt':
|
||||
# from trepan.api import debug; debug()
|
||||
|
||||
if lhs in ('aug_assign1', 'aug_assign2') and ast[0] and ast[0][0] in ('and', 'or'):
|
||||
return True
|
||||
elif lhs in ('raise_stmt1',):
|
||||
# We will assme 'LOAD_ASSERT' will be handled by an assert grammar rule
|
||||
return (tokens[first] == 'LOAD_ASSERT' and
|
||||
(last >= len(tokens) or tokens[last] not in
|
||||
('COME_FROM', 'JUMP_BACK','JUMP_FORWARD')))
|
||||
# We will assume 'LOAD_ASSERT' will be handled by an assert grammar rule
|
||||
return (tokens[first] == 'LOAD_ASSERT' and (last >= len(tokens)))
|
||||
elif rule == ('or', ('expr', 'jmp_true', 'expr', '\\e_come_from_opt')):
|
||||
expr2 = ast[2]
|
||||
return expr2 == 'expr' and expr2[0] == 'LOAD_ASSERT'
|
||||
|
@@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2016-2018 Rocky Bernstein
|
||||
# Copyright (c) 2016-2019 Rocky Bernstein
|
||||
# Copyright (c) 2005 by Dan Pascu <dan@windowmaker.org>
|
||||
# Copyright (c) 2000-2002 by hartmut Goebel <hartmut@goebel.noris.de>
|
||||
|
||||
@@ -228,6 +228,12 @@ class Python27Parser(Python2Parser):
|
||||
tokens[last].pattr == jmp_false.pattr)
|
||||
elif rule[0] == ('raise_stmt1'):
|
||||
return ast[0] == 'expr' and ast[0][0] == 'or'
|
||||
elif rule[0] in ('assert', 'assert2'):
|
||||
jump_inst = ast[1][0]
|
||||
jump_target = jump_inst.attr
|
||||
return not (last >= len(tokens)
|
||||
or jump_target == tokens[last].offset
|
||||
or jump_target == next_offset(ast[-1].op, ast[-1].opc, ast[-1].offset))
|
||||
elif rule == ('list_if_not', ('expr', 'jmp_true', 'list_iter')):
|
||||
jump_inst = ast[1][0]
|
||||
jump_offset = jump_inst.attr
|
||||
|
Reference in New Issue
Block a user