summaryrefslogtreecommitdiff
path: root/Python/compile.c
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2016-09-08 22:01:51 -0700
committerYury Selivanov <yury@magic.io>2016-09-08 22:01:51 -0700
commiteb6364557f9bc4e6be29bb8a8f43308a0e080aba (patch)
tree05b7aed24dce255be67e7a60c021c319d13f43c9 /Python/compile.c
parentb96ef55d493aded2dea18b0208070bdfab4ceb73 (diff)
downloadcpython-git-eb6364557f9bc4e6be29bb8a8f43308a0e080aba.tar.gz
Issue #28003: Implement PEP 525 -- Asynchronous Generators.
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/Python/compile.c b/Python/compile.c
index b46edd4985..faae4f5828 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -1886,8 +1886,6 @@ compiler_function(struct compiler *c, stmt_ty s, int is_async)
return 0;
}
- if (is_async)
- co->co_flags |= CO_COROUTINE;
compiler_make_closure(c, co, funcflags, qualname);
Py_DECREF(qualname);
Py_DECREF(co);
@@ -2801,6 +2799,9 @@ compiler_visit_stmt(struct compiler *c, stmt_ty s)
if (c->u->u_ste->ste_type != FunctionBlock)
return compiler_error(c, "'return' outside function");
if (s->v.Return.value) {
+ if (c->u->u_ste->ste_coroutine && c->u->u_ste->ste_generator)
+ return compiler_error(
+ c, "'return' with value in async generator");
VISIT(c, expr, s->v.Return.value);
}
else
@@ -4115,8 +4116,6 @@ compiler_visit_expr(struct compiler *c, expr_ty e)
case Yield_kind:
if (c->u->u_ste->ste_type != FunctionBlock)
return compiler_error(c, "'yield' outside function");
- if (c->u->u_scope_type == COMPILER_SCOPE_ASYNC_FUNCTION)
- return compiler_error(c, "'yield' inside async function");
if (e->v.Yield.value) {
VISIT(c, expr, e->v.Yield.value);
}
@@ -4992,8 +4991,12 @@ compute_code_flags(struct compiler *c)
flags |= CO_NEWLOCALS | CO_OPTIMIZED;
if (ste->ste_nested)
flags |= CO_NESTED;
- if (ste->ste_generator)
+ if (ste->ste_generator && !ste->ste_coroutine)
flags |= CO_GENERATOR;
+ if (!ste->ste_generator && ste->ste_coroutine)
+ flags |= CO_COROUTINE;
+ if (ste->ste_generator && ste->ste_coroutine)
+ flags |= CO_ASYNC_GENERATOR;
if (ste->ste_varargs)
flags |= CO_VARARGS;
if (ste->ste_varkeywords)