"""def foo():
async def bar():
pass\nawait a
- """]
+ """,
+ """def foo():
+ async for i in arange(2):
+ pass
+ """,
+ """def foo():
+ async with resource:
+ pass
+ """,
+ """async with resource:
+ pass
+ """,
+ """async for i in arange(2):
+ pass
+ """,
+ ]
for code in samples:
with self.subTest(code=code), self.assertRaises(SyntaxError):
basicblock *try, *except, *end, *after_try, *try_cleanup,
*after_loop_else;
+ if (c->u->u_scope_type != COMPILER_SCOPE_ASYNC_FUNCTION) {
+ return compiler_error(c, "'async for' outside async function");
+ }
+
PyObject *stop_aiter_error = _PyUnicode_FromId(&PyId_StopAsyncIteration);
if (stop_aiter_error == NULL) {
return 0;
withitem_ty item = asdl_seq_GET(s->v.AsyncWith.items, pos);
assert(s->kind == AsyncWith_kind);
+ if (c->u->u_scope_type != COMPILER_SCOPE_ASYNC_FUNCTION) {
+ return compiler_error(c, "'async with' outside async function");
+ }
block = compiler_new_block(c);
finally = compiler_new_block(c);