Skip to content

Commit 9a1f123

Browse files
committed
require async for and async with to actually be in an async def method instead of just a generator
1 parent a6e0486 commit 9a1f123

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

py/compile.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,11 +1713,11 @@ STATIC void compile_yield_from(compiler_t *comp) {
17131713
#if MICROPY_PY_ASYNC_AWAIT
17141714
STATIC bool compile_require_async_context(compiler_t *comp, mp_parse_node_struct_t *pns) {
17151715
int scope_flags = comp->scope_cur->scope_flags;
1716-
if(scope_flags & MP_SCOPE_FLAG_GENERATOR) {
1716+
if(scope_flags & MP_SCOPE_FLAG_ASYNC) {
17171717
return true;
17181718
}
17191719
compile_syntax_error(comp, (mp_parse_node_t)pns,
1720-
translate("'async for' or 'async with' outside async function"));
1720+
translate("'await', 'async for' or 'async with' outside async function"));
17211721
return false;
17221722
}
17231723

@@ -2645,6 +2645,7 @@ STATIC void compile_atom_expr_await(compiler_t *comp, mp_parse_node_struct_t *pn
26452645
compile_syntax_error(comp, (mp_parse_node_t)pns, translate("'await' outside function"));
26462646
return;
26472647
}
2648+
compile_require_async_context(comp, pns);
26482649
compile_atom_expr_normal(comp, pns);
26492650
compile_yield_from(comp);
26502651
}

0 commit comments

Comments
 (0)