mirror of
https://github.com/python/cpython.git
synced 2025-09-04 16:01:10 +00:00
Issue #28003: Implement PEP 525 -- Asynchronous Generators.
This commit is contained in:
parent
b96ef55d49
commit
eb6364557f
27 changed files with 2189 additions and 96 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue