summaryrefslogtreecommitdiffstats
path: root/Python/compile.c
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2020-07-06 22:30:20 (GMT)
committerGitHub <noreply@github.com>2020-07-06 22:30:20 (GMT)
commit6488a4a3c9790040059fc5d293e518f193daac8d (patch)
tree9770360402b3512a7ecff3e0028606c402ff275a /Python/compile.c
parent54f115dd533653c43b3c5541bf5936b22e484474 (diff)
downloadcpython-6488a4a3c9790040059fc5d293e518f193daac8d.zip
cpython-6488a4a3c9790040059fc5d293e518f193daac8d.tar.gz
cpython-6488a4a3c9790040059fc5d293e518f193daac8d.tar.bz2
[3.9] bpo-41218: Only mark async code with CO_COROUTINE. (GH-21357) (GH-21362)
3.8.3 had a regression where compiling with ast.PyCF_ALLOW_TOP_LEVEL_AWAIT woudl agressively mark things are coroutine even if there were not. (cherry picked from commit bd46174) Co-authored-by: Matthias Bussonnier <bussonniermatthias@gmail.com> Co-authored-by: Matthias Bussonnier <bussonniermatthias@gmail.com>
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/Python/compile.c b/Python/compile.c
index fccc688..7ec92e0 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -4605,10 +4605,9 @@ compiler_comprehension(struct compiler *c, expr_ty e, int type,
comprehension_ty outermost;
PyObject *qualname = NULL;
int is_async_generator = 0;
+ int top_level_await = IS_TOP_LEVEL_AWAIT(c);
+
- if (IS_TOP_LEVEL_AWAIT(c)) {
- c->u->u_ste->ste_coroutine = 1;
- }
int is_async_function = c->u->u_ste->ste_coroutine;
outermost = (comprehension_ty) asdl_seq_GET(generators, 0);
@@ -4620,7 +4619,7 @@ 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) {
+ if (is_async_generator && !is_async_function && type != COMP_GENEXP && !top_level_await) {
compiler_error(c, "asynchronous comprehension outside of "
"an asynchronous function");
goto error_in_scope;
@@ -4659,6 +4658,9 @@ 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){
+ c->u->u_ste->ste_coroutine = 1;
+ }
if (co == NULL)
goto error;