bpo-33363: raise SyntaxError for async for/with outside async functions (#6616)

This commit is contained in:
Zsolt Dollenstein 2018-04-27 08:58:56 -07:00 committed by Yury Selivanov
parent 078c4e3519
commit e239650660
3 changed files with 25 additions and 1 deletions

View file

@ -2447,6 +2447,10 @@ static int
compiler_async_for(struct compiler *c, stmt_ty s)
{
basicblock *start, *except, *end;
if (c->u->u_scope_type != COMPILER_SCOPE_ASYNC_FUNCTION) {
return compiler_error(c, "'async for' outside async function");
}
start = compiler_new_block(c);
except = compiler_new_block(c);
end = compiler_new_block(c);
@ -4262,6 +4266,9 @@ compiler_async_with(struct compiler *c, stmt_ty s, int pos)
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);