mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
PEP 0492 -- Coroutines with async and await syntax. Issue #24017.
This commit is contained in:
parent
4e6bf4b3da
commit
7544508f02
72 changed files with 9261 additions and 5739 deletions
|
@ -180,7 +180,7 @@ static int symtable_visit_slice(struct symtable *st, slice_ty);
|
|||
static int symtable_visit_params(struct symtable *st, asdl_seq *args);
|
||||
static int symtable_visit_argannotations(struct symtable *st, asdl_seq *args);
|
||||
static int symtable_implicit_arg(struct symtable *st, int pos);
|
||||
static int symtable_visit_annotations(struct symtable *st, stmt_ty s);
|
||||
static int symtable_visit_annotations(struct symtable *st, stmt_ty s, arguments_ty, expr_ty);
|
||||
static int symtable_visit_withitem(struct symtable *st, withitem_ty item);
|
||||
|
||||
|
||||
|
@ -1147,7 +1147,8 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
|
|||
VISIT_SEQ(st, expr, s->v.FunctionDef.args->defaults);
|
||||
if (s->v.FunctionDef.args->kw_defaults)
|
||||
VISIT_SEQ_WITH_NULL(st, expr, s->v.FunctionDef.args->kw_defaults);
|
||||
if (!symtable_visit_annotations(st, s))
|
||||
if (!symtable_visit_annotations(st, s, s->v.FunctionDef.args,
|
||||
s->v.FunctionDef.returns))
|
||||
VISIT_QUIT(st, 0);
|
||||
if (s->v.FunctionDef.decorator_list)
|
||||
VISIT_SEQ(st, expr, s->v.FunctionDef.decorator_list);
|
||||
|
@ -1315,6 +1316,39 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
|
|||
VISIT_SEQ(st, withitem, s->v.With.items);
|
||||
VISIT_SEQ(st, stmt, s->v.With.body);
|
||||
break;
|
||||
case AsyncFunctionDef_kind:
|
||||
if (!symtable_add_def(st, s->v.AsyncFunctionDef.name, DEF_LOCAL))
|
||||
VISIT_QUIT(st, 0);
|
||||
if (s->v.AsyncFunctionDef.args->defaults)
|
||||
VISIT_SEQ(st, expr, s->v.AsyncFunctionDef.args->defaults);
|
||||
if (s->v.AsyncFunctionDef.args->kw_defaults)
|
||||
VISIT_SEQ_WITH_NULL(st, expr,
|
||||
s->v.AsyncFunctionDef.args->kw_defaults);
|
||||
if (!symtable_visit_annotations(st, s, s->v.AsyncFunctionDef.args,
|
||||
s->v.AsyncFunctionDef.returns))
|
||||
VISIT_QUIT(st, 0);
|
||||
if (s->v.AsyncFunctionDef.decorator_list)
|
||||
VISIT_SEQ(st, expr, s->v.AsyncFunctionDef.decorator_list);
|
||||
if (!symtable_enter_block(st, s->v.AsyncFunctionDef.name,
|
||||
FunctionBlock, (void *)s, s->lineno,
|
||||
s->col_offset))
|
||||
VISIT_QUIT(st, 0);
|
||||
VISIT(st, arguments, s->v.AsyncFunctionDef.args);
|
||||
VISIT_SEQ(st, stmt, s->v.AsyncFunctionDef.body);
|
||||
if (!symtable_exit_block(st, s))
|
||||
VISIT_QUIT(st, 0);
|
||||
break;
|
||||
case AsyncWith_kind:
|
||||
VISIT_SEQ(st, withitem, s->v.AsyncWith.items);
|
||||
VISIT_SEQ(st, stmt, s->v.AsyncWith.body);
|
||||
break;
|
||||
case AsyncFor_kind:
|
||||
VISIT(st, expr, s->v.AsyncFor.target);
|
||||
VISIT(st, expr, s->v.AsyncFor.iter);
|
||||
VISIT_SEQ(st, stmt, s->v.AsyncFor.body);
|
||||
if (s->v.AsyncFor.orelse)
|
||||
VISIT_SEQ(st, stmt, s->v.AsyncFor.orelse);
|
||||
break;
|
||||
}
|
||||
VISIT_QUIT(st, 1);
|
||||
}
|
||||
|
@ -1392,6 +1426,10 @@ symtable_visit_expr(struct symtable *st, expr_ty e)
|
|||
VISIT(st, expr, e->v.YieldFrom.value);
|
||||
st->st_cur->ste_generator = 1;
|
||||
break;
|
||||
case Await_kind:
|
||||
VISIT(st, expr, e->v.Await.value);
|
||||
st->st_cur->ste_generator = 1;
|
||||
break;
|
||||
case Compare_kind:
|
||||
VISIT(st, expr, e->v.Compare.left);
|
||||
VISIT_SEQ(st, expr, e->v.Compare.comparators);
|
||||
|
@ -1492,10 +1530,9 @@ symtable_visit_argannotations(struct symtable *st, asdl_seq *args)
|
|||
}
|
||||
|
||||
static int
|
||||
symtable_visit_annotations(struct symtable *st, stmt_ty s)
|
||||
symtable_visit_annotations(struct symtable *st, stmt_ty s,
|
||||
arguments_ty a, expr_ty returns)
|
||||
{
|
||||
arguments_ty a = s->v.FunctionDef.args;
|
||||
|
||||
if (a->args && !symtable_visit_argannotations(st, a->args))
|
||||
return 0;
|
||||
if (a->vararg && a->vararg->annotation)
|
||||
|
@ -1504,7 +1541,7 @@ symtable_visit_annotations(struct symtable *st, stmt_ty s)
|
|||
VISIT(st, expr, a->kwarg->annotation);
|
||||
if (a->kwonlyargs && !symtable_visit_argannotations(st, a->kwonlyargs))
|
||||
return 0;
|
||||
if (s->v.FunctionDef.returns)
|
||||
if (returns)
|
||||
VISIT(st, expr, s->v.FunctionDef.returns);
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue