From bd46174a5a09a54e5ae1077909f923f56a7cf710 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Mon, 6 Jul 2020 14:26:52 -0700 Subject: bpo-41218: Only mark async code with CO_COROUTINE. (#21357) 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. --- Python/compile.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'Python/compile.c') diff --git a/Python/compile.c b/Python/compile.c index 4a9b511961..1b94f0656d 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -4588,10 +4588,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); @@ -4603,7 +4602,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; @@ -4642,6 +4641,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; -- cgit v1.2.1