|
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; |
@@ -2682,7 +2686,7 @@ static int |
2682 | 2686 | compiler_async_for(struct compiler *c, stmt_ty s) |
2683 | 2687 | { |
2684 | 2688 | basicblock *start, *except, *end; |
2685 | | - if (c->c_flags->cf_flags & PyCF_ALLOW_TOP_LEVEL_AWAIT){ |
| 2689 | + if (IS_TOP_LEVEL_AWAIT(c)){ |
2686 | 2690 | c->u->u_ste->ste_coroutine = 1; |
2687 | 2691 | } else if (c->u->u_scope_type != COMPILER_SCOPE_ASYNC_FUNCTION) { |
2688 | 2692 | return compiler_error(c, "'async for' outside async function"); |
@@ -4666,7 +4670,7 @@ compiler_async_with(struct compiler *c, stmt_ty s, int pos) |
4666 | 4670 | withitem_ty item = asdl_seq_GET(s->v.AsyncWith.items, pos); |
4667 | 4671 |
|
4668 | 4672 | assert(s->kind == AsyncWith_kind); |
4669 | | - if (c->c_flags->cf_flags & PyCF_ALLOW_TOP_LEVEL_AWAIT){ |
| 4673 | + if (IS_TOP_LEVEL_AWAIT(c)){ |
4670 | 4674 | c->u->u_ste->ste_coroutine = 1; |
4671 | 4675 | } else if (c->u->u_scope_type != COMPILER_SCOPE_ASYNC_FUNCTION){ |
4672 | 4676 | return compiler_error(c, "'async with' outside async function"); |
@@ -4877,7 +4881,7 @@ compiler_visit_expr1(struct compiler *c, expr_ty e) |
4877 | 4881 | ADDOP(c, YIELD_FROM); |
4878 | 4882 | break; |
4879 | 4883 | case Await_kind: |
4880 | | - if (!(c->c_flags->cf_flags & PyCF_ALLOW_TOP_LEVEL_AWAIT)){ |
| 4884 | + if (!IS_TOP_LEVEL_AWAIT(c)){ |
4881 | 4885 | if (c->u->u_ste->ste_type != FunctionBlock){ |
4882 | 4886 | return compiler_error(c, "'await' outside function"); |
4883 | 4887 | } |
@@ -5820,7 +5824,7 @@ compute_code_flags(struct compiler *c) |
5820 | 5824 | /* (Only) inherit compilerflags in PyCF_MASK */ |
5821 | 5825 | flags |= (c->c_flags->cf_flags & PyCF_MASK); |
5822 | 5826 |
|
5823 | | - if ((c->c_flags->cf_flags & PyCF_ALLOW_TOP_LEVEL_AWAIT) && |
| 5827 | + if ((IS_TOP_LEVEL_AWAIT(c)) && |
5824 | 5828 | ste->ste_coroutine && |
5825 | 5829 | !ste->ste_generator) { |
5826 | 5830 | flags |= CO_COROUTINE; |
|
0 commit comments