You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 16:59:52 +08:00
3.x ""raise AssertionError" vs "assert"
Not sure this is totally correct yet.
This commit is contained in:
@@ -12,11 +12,18 @@ assert isinstance(1, int)
|
|||||||
# 2.6
|
# 2.6
|
||||||
# assert2 ::= assert_expr jmp_true LOAD_ASSERT expr RAISE_VARARGS_2 come_from_pop
|
# assert2 ::= assert_expr jmp_true LOAD_ASSERT expr RAISE_VARARGS_2 come_from_pop
|
||||||
|
|
||||||
for method_name in self:
|
for method_name in ['a']:
|
||||||
if method_name in self:
|
if method_name in ('b',):
|
||||||
method = 'a'
|
method = 'a'
|
||||||
else:
|
else:
|
||||||
assert 0, "instance installed"
|
assert 0, "instance installed"
|
||||||
|
|
||||||
methods = 'b'
|
methods = 'b'
|
||||||
#
|
|
||||||
|
# _Bug in 3.x is not recognizing the assert
|
||||||
|
# producing:
|
||||||
|
# if not not do_setlocal:
|
||||||
|
# raise AssertError
|
||||||
|
|
||||||
|
def getpreferredencoding(do_setlocale=True):
|
||||||
|
assert not do_setlocale
|
||||||
|
@@ -133,6 +133,7 @@ class Scanner3(scan.Scanner):
|
|||||||
|
|
||||||
bytecode = Bytecode(co, self.opc)
|
bytecode = Bytecode(co, self.opc)
|
||||||
|
|
||||||
|
# FIXME: put as its own method?
|
||||||
# Scan for assertions. Later we will
|
# Scan for assertions. Later we will
|
||||||
# turn 'LOAD_GLOBAL' to 'LOAD_ASSERT'.
|
# turn 'LOAD_GLOBAL' to 'LOAD_ASSERT'.
|
||||||
# 'LOAD_ASSERT' is used in assert statements.
|
# 'LOAD_ASSERT' is used in assert statements.
|
||||||
@@ -143,13 +144,23 @@ class Scanner3(scan.Scanner):
|
|||||||
inst = bs[i]
|
inst = bs[i]
|
||||||
|
|
||||||
# We need to detect the difference between
|
# We need to detect the difference between
|
||||||
# "raise AssertionError" and
|
# "raise AssertionError" and "assert"
|
||||||
# "assert"
|
# If we have a JUMP_FORWARD after the
|
||||||
if inst.opname == 'POP_JUMP_IF_TRUE' and i+3 < n:
|
# RAISE_VARARGS then we have a "raise" statement
|
||||||
next_inst = bs[i+3]
|
# else we have an "assert" statement.
|
||||||
|
if inst.opname == 'POP_JUMP_IF_TRUE' and i+1 < n:
|
||||||
|
next_inst = bs[i+1]
|
||||||
if (next_inst.opname == 'LOAD_GLOBAL' and
|
if (next_inst.opname == 'LOAD_GLOBAL' and
|
||||||
next_inst.argval == 'AssertionError'):
|
next_inst.argval == 'AssertionError'):
|
||||||
self.load_asserts.add(next_inst.offset)
|
for j in range(i+2, n):
|
||||||
|
raise_inst = bs[j]
|
||||||
|
if raise_inst.opname.startswith('RAISE_VARARGS'):
|
||||||
|
if j+1 >= n or bs[j+1].opname != 'JUMP_FORWARD':
|
||||||
|
self.load_asserts.add(next_inst.offset)
|
||||||
|
pass
|
||||||
|
break
|
||||||
|
pass
|
||||||
|
pass
|
||||||
|
|
||||||
# Get jump targets
|
# Get jump targets
|
||||||
# Format: {target offset: [jump offsets]}
|
# Format: {target offset: [jump offsets]}
|
||||||
|
Reference in New Issue
Block a user