{
location loc = LOC(s);
if (IS_TOP_LEVEL_AWAIT(c)){
- c->u->u_ste->ste_coroutine = 1;
+ assert(c->u->u_ste->ste_coroutine == 1);
} else if (c->u->u_scope_type != COMPILER_SCOPE_ASYNC_FUNCTION) {
return compiler_error(c, loc, "'async for' outside async function");
}
co = optimize_and_assemble(c, 1);
compiler_exit_scope(c);
if (is_top_level_await && is_async_generator){
- c->u->u_ste->ste_coroutine = 1;
+ assert(c->u->u_ste->ste_coroutine == 1);
}
if (co == NULL) {
goto error;
assert(s->kind == AsyncWith_kind);
if (IS_TOP_LEVEL_AWAIT(c)){
- c->u->u_ste->ste_coroutine = 1;
+ assert(c->u->u_ste->ste_coroutine == 1);
} else if (c->u->u_scope_type != COMPILER_SCOPE_ASYNC_FUNCTION){
return compiler_error(c, loc, "'async with' outside async function");
}
return 1;
}
+static void
+maybe_set_ste_coroutine_for_module(struct symtable *st, stmt_ty s)
+{
+ if ((st->st_future->ff_features & PyCF_ALLOW_TOP_LEVEL_AWAIT) &&
+ (st->st_cur->ste_type == ModuleBlock))
+ {
+ st->st_cur->ste_coroutine = 1;
+ }
+}
+
static int
symtable_visit_stmt(struct symtable *st, stmt_ty s)
{
break;
}
case AsyncWith_kind:
+ maybe_set_ste_coroutine_for_module(st, s);
VISIT_SEQ(st, withitem, s->v.AsyncWith.items);
VISIT_SEQ(st, stmt, s->v.AsyncWith.body);
break;
case AsyncFor_kind:
+ maybe_set_ste_coroutine_for_module(st, s);
VISIT(st, expr, s->v.AsyncFor.target);
VISIT(st, expr, s->v.AsyncFor.iter);
VISIT_SEQ(st, stmt, s->v.AsyncFor.body);