@@ -4551,7 +4551,9 @@ compiler_async_with(struct compiler *c, stmt_ty s, int pos)
4551
4551
4552
4552
assert (s -> kind == AsyncWith_kind );
4553
4553
if (c -> u -> u_scope_type != COMPILER_SCOPE_ASYNC_FUNCTION ) {
4554
- return compiler_error (c , "'async with' outside async function" );
4554
+ if (!(c -> c_flags -> cf_flags & 0x2000 )) {
4555
+ return compiler_error (c , "'async with' outside async function" );
4556
+ }
4555
4557
}
4556
4558
4557
4559
block = compiler_new_block (c );
@@ -4759,12 +4761,19 @@ compiler_visit_expr1(struct compiler *c, expr_ty e)
4759
4761
ADDOP (c , YIELD_FROM );
4760
4762
break ;
4761
4763
case Await_kind :
4762
- if (c -> u -> u_ste -> ste_type != FunctionBlock )
4763
- return compiler_error (c , "'await' outside function" );
4764
+ if (c -> u -> u_ste -> ste_type != FunctionBlock ) {
4765
+ if (!(c -> c_flags -> cf_flags & 0x2000 )) {
4766
+ return compiler_error (c , "'await' outside function" );
4767
+ }
4768
+
4769
+ c -> u -> u_ste -> ste_coroutine = 1 ;
4770
+ }
4764
4771
4765
- if (c -> u -> u_scope_type != COMPILER_SCOPE_ASYNC_FUNCTION &&
4766
- c -> u -> u_scope_type != COMPILER_SCOPE_COMPREHENSION )
4767
- return compiler_error (c , "'await' outside async function" );
4772
+ if (!(c -> c_flags -> cf_flags & 0x2000 )) {
4773
+ if (c -> u -> u_scope_type != COMPILER_SCOPE_ASYNC_FUNCTION &&
4774
+ c -> u -> u_scope_type != COMPILER_SCOPE_COMPREHENSION )
4775
+ return compiler_error (c , "'await' outside async function" );
4776
+ }
4768
4777
4769
4778
VISIT (c , expr , e -> v .Await .value );
4770
4779
ADDOP (c , GET_AWAITABLE );
@@ -5699,6 +5708,10 @@ compute_code_flags(struct compiler *c)
5699
5708
/* (Only) inherit compilerflags in PyCF_MASK */
5700
5709
flags |= (c -> c_flags -> cf_flags & PyCF_MASK );
5701
5710
5711
+ if ((c -> c_flags -> cf_flags & 0x2000 ) && c -> u -> u_ste -> ste_coroutine ) {
5712
+ flags |= CO_COROUTINE ;
5713
+ }
5714
+
5702
5715
return flags ;
5703
5716
}
5704
5717
0 commit comments