summaryrefslogtreecommitdiffstats
path: root/Python/symtable.c
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2024-07-03 09:18:34 (GMT)
committerGitHub <noreply@github.com>2024-07-03 09:18:34 (GMT)
commit93156880efd14ad7adc7d3512552b434f5543890 (patch)
tree3aa74dce4d254c324c36497dcd9a44f1d0d8ca9a /Python/symtable.c
parent51c4a324c037fb2e31640202243fd1c8b33800d5 (diff)
downloadcpython-93156880efd14ad7adc7d3512552b434f5543890.zip
cpython-93156880efd14ad7adc7d3512552b434f5543890.tar.gz
cpython-93156880efd14ad7adc7d3512552b434f5543890.tar.bz2
gh-121272: set ste_coroutine during symtable construction (#121297)
compiler no longer modifies the symtable after this.
Diffstat (limited to 'Python/symtable.c')
-rw-r--r--Python/symtable.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/Python/symtable.c b/Python/symtable.c
index 61fa5c6..65677f8 100644
--- a/Python/symtable.c
+++ b/Python/symtable.c
@@ -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)
{
@@ -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);