Skip to content

gh-121272: compiler no longer modifies the symtable, ste_coroutine always set during symtable construction #121297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -3059,7 +3059,7 @@ compiler_async_for(struct compiler *c, stmt_ty s)
{
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");
}
Expand Down Expand Up @@ -5782,7 +5782,7 @@ compiler_comprehension(struct compiler *c, expr_ty e, int type,
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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this assignment has been obsolete for a while now, see #6766 (comment).

}
if (co == NULL) {
goto error;
Expand Down Expand Up @@ -5926,7 +5926,7 @@ compiler_async_with(struct compiler *c, stmt_ty s, int pos)

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");
}
Expand Down
12 changes: 12 additions & 0 deletions Python/symtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -1681,6 +1681,16 @@ check_import_from(struct symtable *st, stmt_ty s)
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)
{
Expand Down Expand Up @@ -2074,10 +2084,12 @@ 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);
Expand Down
Loading