@@ -133,6 +133,7 @@ def disassemble(self, co, classname=None, code_objects={}, show_asm=None):
133133
134134 bytecode = Bytecode (co , self .opc )
135135
136+ # FIXME: put as its own method?
136137 # Scan for assertions. Later we will
137138 # turn 'LOAD_GLOBAL' to 'LOAD_ASSERT'.
138139 # 'LOAD_ASSERT' is used in assert statements.
@@ -143,13 +144,23 @@ def disassemble(self, co, classname=None, code_objects={}, show_asm=None):
143144 inst = bs [i ]
144145
145146 # We need to detect the difference between
146- # "raise AssertionError" and
147- # "assert"
148- if inst .opname == 'POP_JUMP_IF_TRUE' and i + 3 < n :
149- next_inst = bs [i + 3 ]
147+ # "raise AssertionError" and "assert"
148+ # If we have a JUMP_FORWARD after the
149+ # RAISE_VARARGS then we have a "raise" statement
150+ # else we have an "assert" statement.
151+ if inst .opname == 'POP_JUMP_IF_TRUE' and i + 1 < n :
152+ next_inst = bs [i + 1 ]
150153 if (next_inst .opname == 'LOAD_GLOBAL' and
151154 next_inst .argval == 'AssertionError' ):
152- self .load_asserts .add (next_inst .offset )
155+ for j in range (i + 2 , n ):
156+ raise_inst = bs [j ]
157+ if raise_inst .opname .startswith ('RAISE_VARARGS' ):
158+ if j + 1 >= n or bs [j + 1 ].opname != 'JUMP_FORWARD' :
159+ self .load_asserts .add (next_inst .offset )
160+ pass
161+ break
162+ pass
163+ pass
153164
154165 # Get jump targets
155166 # Format: {target offset: [jump offsets]}
0 commit comments