summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2021-07-13 21:27:50 (GMT)
committerGitHub <noreply@github.com>2021-07-13 21:27:50 (GMT)
commit054e9c84ac7c394941bba3ea1829d14dce1243fc (patch)
treeedd3cbe6ed6083909280d8aaed50c8d2679b4fde /Python
parent0ee0a740e12ec8568aafa033aa6bb08b265afe26 (diff)
downloadcpython-054e9c84ac7c394941bba3ea1829d14dce1243fc.zip
cpython-054e9c84ac7c394941bba3ea1829d14dce1243fc.tar.gz
cpython-054e9c84ac7c394941bba3ea1829d14dce1243fc.tar.bz2
bpo-33346: Allow async comprehensions inside implicit async comprehensions (GH-6766)
Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
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