summaryrefslogtreecommitdiffstats
path: root/Python/compile.c
diff options
context:
space:
mode:
authorZsolt Dollenstein <zsol.zsol@gmail.com>2018-04-27 22:33:37 (GMT)
committerYury Selivanov <yury@magic.io>2018-04-27 22:33:37 (GMT)
commita93a663d6c2fdfbddbda9729c96e2737c0012522 (patch)
treece34cb81abd313b5721b9edd1890da7a70185e14 /Python/compile.c
parentdd3ede7537653a62815c2fedbb67d6f2fb870d4c (diff)
downloadcpython-a93a663d6c2fdfbddbda9729c96e2737c0012522.zip
cpython-a93a663d6c2fdfbddbda9729c96e2737c0012522.tar.gz
cpython-a93a663d6c2fdfbddbda9729c96e2737c0012522.tar.bz2
[3.7] bpo-33363: raise SyntaxError for async for/with outside async functions (GH-6616). (GH-6619)
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/Python/compile.c b/Python/compile.c
index d4245e2..62d7886 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -2339,6 +2339,10 @@ compiler_async_for(struct compiler *c, stmt_ty s)
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;
@@ -4204,6 +4208,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);