Skip to content

Commit 24df30c

Browse files
committed
py/compile: Don't compile assert statements when optimisations enabled.
As per CPython.
1 parent fc73c9b commit 24df30c

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

py/compile.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,11 @@ STATIC void compile_nonlocal_stmt(compiler_t *comp, mp_parse_node_struct_t *pns)
12001200
}
12011201

12021202
STATIC void compile_assert_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
1203+
// with optimisations enabled we don't compile assertions
1204+
if (MP_STATE_VM(mp_optimise_value) != 0) {
1205+
return;
1206+
}
1207+
12031208
uint l_end = comp_next_label(comp);
12041209
c_if_cond(comp, pns->nodes[0], true, l_end);
12051210
EMIT_LOAD_GLOBAL(MP_QSTR_AssertionError); // we load_global instead of load_id, to be consistent with CPython

0 commit comments

Comments
 (0)