summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
Diffstat (limited to 'Python')
-rw-r--r--Python/compile.c14
-rw-r--r--Python/symtable.c9
2 files changed, 16 insertions, 7 deletions
diff --git a/Python/compile.c b/Python/compile.c
index 1feb97c..bb5c2ec 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -4947,11 +4947,9 @@ compiler_comprehension(struct compiler *c, expr_ty e, int type,
PyCodeObject *co = NULL;
comprehension_ty outermost;
PyObject *qualname = NULL;
+ int scope_type = c->u->u_scope_type;
int is_async_generator = 0;
- int top_level_await = IS_TOP_LEVEL_AWAIT(c);
-
-
- int is_async_function = c->u->u_ste->ste_coroutine;
+ int is_top_level_await = IS_TOP_LEVEL_AWAIT(c);
outermost = (comprehension_ty) asdl_seq_GET(generators, 0);
if (!compiler_enter_scope(c, name, COMPILER_SCOPE_COMPREHENSION,
@@ -4963,7 +4961,11 @@ compiler_comprehension(struct compiler *c, expr_ty e, int type,
is_async_generator = c->u->u_ste->ste_coroutine;
- if (is_async_generator && !is_async_function && type != COMP_GENEXP && !top_level_await) {
+ if (is_async_generator && type != COMP_GENEXP &&
+ scope_type != COMPILER_SCOPE_ASYNC_FUNCTION &&
+ scope_type != COMPILER_SCOPE_COMPREHENSION &&
+ !is_top_level_await)
+ {
compiler_error(c, "asynchronous comprehension outside of "
"an asynchronous function");
goto error_in_scope;
@@ -5002,7 +5004,7 @@ compiler_comprehension(struct compiler *c, expr_ty e, int type,
qualname = c->u->u_qualname;
Py_INCREF(qualname);
compiler_exit_scope(c);
- if (top_level_await && is_async_generator){
+ if (is_top_level_await && is_async_generator){
c->u->u_ste->ste_coroutine = 1;
}
if (co == NULL)
diff --git a/Python/symtable.c b/Python/symtable.c
index 4508464..64c1635 100644
--- a/Python/symtable.c
+++ b/Python/symtable.c
@@ -2056,7 +2056,14 @@ symtable_handle_comprehension(struct symtable *st, expr_ty e,
return 0;
}
st->st_cur->ste_generator = is_generator;
- return symtable_exit_block(st);
+ int is_async = st->st_cur->ste_coroutine && !is_generator;
+ if (!symtable_exit_block(st)) {
+ return 0;
+ }
+ if (is_async) {
+ st->st_cur->ste_coroutine = 1;
+ }
+ return 1;
}
static int