diff --git a/py/compile.c b/py/compile.c index 4aaa68e6ced1b5056a2e4c061374ac419047cf51..e660e668c438cbf4b090a06c813705f9bde3c9fe 100644 --- a/py/compile.c +++ b/py/compile.c @@ -1830,7 +1830,7 @@ STATIC void compile_async_with_stmt_helper(compiler_t *comp, int n, mp_parse_nod // Detect if TOS an exception or not EMIT(dup_top); - EMIT_LOAD_GLOBAL(MP_QSTR_Exception); + EMIT_LOAD_GLOBAL(MP_QSTR_BaseException); EMIT_ARG(binary_op, MP_BINARY_OP_EXCEPTION_MATCH); EMIT_ARG(pop_jump_if, false, l_ret_unwind_jump); // if not an exception then we have case 3 diff --git a/tests/basics/async_with.py b/tests/basics/async_with.py index 5af0c5d955ccb597d8da0a9d6b7c5c794405b68e..f7774055cf46ad87e27727416c288c0e37244488 100644 --- a/tests/basics/async_with.py +++ b/tests/basics/async_with.py @@ -27,3 +27,13 @@ try: o.send(None) except ValueError: print('ValueError') + +# test raising BaseException to make sure it is handled by the async-with +async def h(): + async with AContext(): + raise BaseException +o = h() +try: + o.send(None) +except BaseException: + print('BaseException') diff --git a/tests/basics/async_with.py.exp b/tests/basics/async_with.py.exp index d00b18c9693e20bd6a34c66639c378cc061edb3c..6bbf84cb4b52cb390d9c3d206956e3b8c8d496c2 100644 --- a/tests/basics/async_with.py.exp +++ b/tests/basics/async_with.py.exp @@ -6,3 +6,6 @@ enter 1 exit <class 'ValueError'> error ValueError +enter +exit <class 'BaseException'> +BaseException