diff --git a/test/simple_source/stmts/15_assert.py b/test/simple_source/stmts/15_assert.py index 08d64044..c16b1385 100644 --- a/test/simple_source/stmts/15_assert.py +++ b/test/simple_source/stmts/15_assert.py @@ -12,11 +12,18 @@ assert isinstance(1, int) # 2.6 # assert2 ::= assert_expr jmp_true LOAD_ASSERT expr RAISE_VARARGS_2 come_from_pop -for method_name in self: - if method_name in self: +for method_name in ['a']: + if method_name in ('b',): method = 'a' else: assert 0, "instance installed" 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 diff --git a/uncompyle6/scanners/scanner3.py b/uncompyle6/scanners/scanner3.py index 1f81d313..ce49ed87 100644 --- a/uncompyle6/scanners/scanner3.py +++ b/uncompyle6/scanners/scanner3.py @@ -133,6 +133,7 @@ class Scanner3(scan.Scanner): bytecode = Bytecode(co, self.opc) + # FIXME: put as its own method? # Scan for assertions. Later we will # turn 'LOAD_GLOBAL' to 'LOAD_ASSERT'. # 'LOAD_ASSERT' is used in assert statements. @@ -143,13 +144,23 @@ class Scanner3(scan.Scanner): inst = bs[i] # We need to detect the difference between - # "raise AssertionError" and - # "assert" - if inst.opname == 'POP_JUMP_IF_TRUE' and i+3 < n: - next_inst = bs[i+3] + # "raise AssertionError" and "assert" + # If we have a JUMP_FORWARD after the + # RAISE_VARARGS then we have a "raise" statement + # 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 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 # Format: {target offset: [jump offsets]}