|
41 | 41 | #define COMP_SETCOMP 2 |
42 | 42 | #define COMP_DICTCOMP 3 |
43 | 43 |
|
| 44 | +#define IS_TOP_LEVEL_AWAIT(c) ( \ |
| 45 | + (c->c_flags->cf_flags & PyCF_ALLOW_TOP_LEVEL_AWAIT) \ |
| 46 | + && (c->u->u_ste->ste_type == ModuleBlock)) |
| 47 | + |
44 | 48 | struct instr { |
45 | 49 | unsigned i_jabs : 1; |
46 | 50 | unsigned i_jrel : 1; |
@@ -2743,7 +2747,7 @@ static int |
2743 | 2747 | compiler_async_for(struct compiler *c, stmt_ty s) |
2744 | 2748 | { |
2745 | 2749 | basicblock *start, *except, *end; |
2746 | | - if (c->c_flags->cf_flags & PyCF_ALLOW_TOP_LEVEL_AWAIT){ |
| 2750 | + if (IS_TOP_LEVEL_AWAIT(c)){ |
2747 | 2751 | c->u->u_ste->ste_coroutine = 1; |
2748 | 2752 | } else if (c->u->u_scope_type != COMPILER_SCOPE_ASYNC_FUNCTION) { |
2749 | 2753 | return compiler_error(c, "'async for' outside async function"); |
@@ -4789,7 +4793,7 @@ compiler_async_with(struct compiler *c, stmt_ty s, int pos) |
4789 | 4793 | withitem_ty item = asdl_seq_GET(s->v.AsyncWith.items, pos); |
4790 | 4794 |
|
4791 | 4795 | assert(s->kind == AsyncWith_kind); |
4792 | | - if (c->c_flags->cf_flags & PyCF_ALLOW_TOP_LEVEL_AWAIT){ |
| 4796 | + if (IS_TOP_LEVEL_AWAIT(c)){ |
4793 | 4797 | c->u->u_ste->ste_coroutine = 1; |
4794 | 4798 | } else if (c->u->u_scope_type != COMPILER_SCOPE_ASYNC_FUNCTION){ |
4795 | 4799 | return compiler_error(c, "'async with' outside async function"); |
@@ -5007,7 +5011,7 @@ compiler_visit_expr1(struct compiler *c, expr_ty e) |
5007 | 5011 | ADDOP(c, YIELD_FROM); |
5008 | 5012 | break; |
5009 | 5013 | case Await_kind: |
5010 | | - if (!(c->c_flags->cf_flags & PyCF_ALLOW_TOP_LEVEL_AWAIT)){ |
| 5014 | + if (!IS_TOP_LEVEL_AWAIT(c)){ |
5011 | 5015 | if (c->u->u_ste->ste_type != FunctionBlock){ |
5012 | 5016 | return compiler_error(c, "'await' outside function"); |
5013 | 5017 | } |
@@ -5836,7 +5840,7 @@ compute_code_flags(struct compiler *c) |
5836 | 5840 | /* (Only) inherit compilerflags in PyCF_MASK */ |
5837 | 5841 | flags |= (c->c_flags->cf_flags & PyCF_MASK); |
5838 | 5842 |
|
5839 | | - if ((c->c_flags->cf_flags & PyCF_ALLOW_TOP_LEVEL_AWAIT) && |
| 5843 | + if ((IS_TOP_LEVEL_AWAIT(c)) && |
5840 | 5844 | ste->ste_coroutine && |
5841 | 5845 | !ste->ste_generator) { |
5842 | 5846 | flags |= CO_COROUTINE; |
|
0 commit comments