diff options
author | Zsolt Dollenstein <zsol.zsol@gmail.com> | 2018-04-27 15:58:56 (GMT) |
---|---|---|
committer | Yury Selivanov <yury@magic.io> | 2018-04-27 15:58:56 (GMT) |
commit | e2396506606115e785c94ec129eb86e2ed0aa744 (patch) | |
tree | ceee4cab03aeb3f211ffbc7039fc16981be15e40 /Python/compile.c | |
parent | 078c4e3519deeef8014541925da057bb064eb5a8 (diff) | |
download | cpython-e2396506606115e785c94ec129eb86e2ed0aa744.zip cpython-e2396506606115e785c94ec129eb86e2ed0aa744.tar.gz cpython-e2396506606115e785c94ec129eb86e2ed0aa744.tar.bz2 |
bpo-33363: raise SyntaxError for async for/with outside async functions (#6616)
Diffstat (limited to 'Python/compile.c')
-rw-r--r-- | Python/compile.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/Python/compile.c b/Python/compile.c index cc0988f..7960f09 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -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); |