Python 3.15a1 3651 (Simplify LOAD_CONST)
Python 3.15a1 3652 (Virtual iterators)
Python 3.15a1 3653 (Fix handling of opcodes that may leave operands on the stack when optimizing LOAD_FAST)
+ Python 3.15a1 3654 (Fix missing exception handlers in logical expression)
Python 3.16 will start with 3700
*/
-#define PYC_MAGIC_NUMBER 3653
+#define PYC_MAGIC_NUMBER 3654
/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes
(little-endian) and then appending b'\r\n'. */
#define PYC_MAGIC_NUMBER_TOKEN \
self.assertIs(res, v[3])
self.assertEqual([e.called for e in v], [1, 1, 0, 1, 0])
+ def test_exception(self):
+ # See gh-137288
+ class Foo:
+ def __bool__(self):
+ raise NotImplementedError()
+
+ a = Foo()
+ b = Foo()
+
+ with self.assertRaises(NotImplementedError):
+ bool(a)
+
+ with self.assertRaises(NotImplementedError):
+ c = a or b
+
@requires_debug_ranges()
class TestSourcePositions(unittest.TestCase):
# Ensure that compiled code snippets have correct line and column numbers
--- /dev/null
+Fix bug where some bytecode instructions of a boolean expression are not
+associated with the correct exception handler.
instr->i_opcode = instr->i_opcode == JUMP_IF_FALSE ?
POP_JUMP_IF_FALSE : POP_JUMP_IF_TRUE;
location loc = instr->i_loc;
+ basicblock *except = instr->i_except;
cfg_instr copy = {
.i_opcode = COPY,
.i_oparg = 1,
.i_loc = loc,
.i_target = NULL,
+ .i_except = except,
};
RETURN_IF_ERROR(basicblock_insert_instruction(b, i++, ©));
cfg_instr to_bool = {
.i_oparg = 0,
.i_loc = loc,
.i_target = NULL,
+ .i_except = except,
};
RETURN_IF_ERROR(basicblock_insert_instruction(b, i++, &to_bool));
}
.i_oparg = 0,
.i_loc = loc,
.i_target = NULL,
+ .i_except = NULL,
};
RETURN_IF_ERROR(basicblock_insert_instruction(entryblock, 0, &make_gen));
cfg_instr pop_top = {
.i_oparg = 0,
.i_loc = loc,
.i_target = NULL,
+ .i_except = NULL,
};
RETURN_IF_ERROR(basicblock_insert_instruction(entryblock, 1, &pop_top));
}
.i_oparg = oldindex,
.i_loc = NO_LOCATION,
.i_target = NULL,
+ .i_except = NULL,
};
if (basicblock_insert_instruction(entryblock, ncellsused, &make_cell) < 0) {
PyMem_RawFree(sorted);
.i_oparg = nfreevars,
.i_loc = NO_LOCATION,
.i_target = NULL,
+ .i_except = NULL,
};
RETURN_IF_ERROR(basicblock_insert_instruction(entryblock, 0, ©_frees));
}