8000 support async def · python/cpython@21e1b1a · GitHub
[go: up one dir, main page]

Skip to content

Commit 21e1b1a

Browse files
committed
support async def
1 parent e36c5f5 commit 21e1b1a

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

Python/compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2211,7 +2211,7 @@ compiler_function(struct compiler *c, stmt_ty s, int is_async)
22112211
if (!typeparams_name) {
22122212
return ERROR;
22132213
}
2214-
if (compiler_enter_scope(c, typeparams_name, scope_type,
2214+
if (compiler_enter_scope(c, typeparams_name, COMPILER_SCOPE_FUNCTION,
22152215
(void *)typeparams, firstlineno) == -1) {
22162216
Py_DECREF(typeparams_name);
22172217
return ERROR;

Python/symtable.c

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,11 +1488,42 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
14881488
if (s->v.AsyncFunctionDef.args->kw_defaults)
14891489
VISIT_SEQ_WITH_NULL(st, expr,
14901490
s->v.AsyncFunctionDef.args->kw_defaults);
1491+
if (s->v.AsyncFunctionDef.decorator_list)
1492+
VISIT_SEQ(st, expr, s->v.AsyncFunctionDef.decorator_list);
1493+
if (s->v.AsyncFunctionDef.typeparams) {
1494+
if (!symtable_enter_block(st, s->v.AsyncFunctionDef.name,
1495+
FunctionBlock, (void *)s->v.AsyncFunctionDef.typeparams,
1496+
LOCATION(s))) {
1497+
VISIT_QUIT(st, 0);
1498+
}
1499+
if (s->v.AsyncFunctionDef.args->defaults) {
1500+
PyObject *defaults_name = PyUnicode_FromString(".defaults");
1501+
if (defaults_name == NULL) {
1502+
VISIT_QUIT(st, 0);
1503+
}
1504+
if (!symtable_add_def(st, defaults_name, DEF_PARAM, LOCATION(s))) {
1505+
8000 Py_DECREF(defaults_name);
1506+
VISIT_QUIT(st, 0);
1507+
}
1508+
Py_DECREF(defaults_name);
1509+
}
1510+
if (has_kwonlydefaults(s->v.AsyncFunctionDef.args->kwonlyargs,
1511+
s->v.AsyncFunctionDef.args->kw_defaults)) {
1512+
PyObject *kwonly_name = PyUnicode_FromString(".kwonlydefaults");
1513+
if (kwonly_name == NULL) {
1514+
VISIT_QUIT(st, 0);
1515+
}
1516+
if (!symtable_add_def(st, kwonly_name, DEF_PARAM, LOCATION(s))) {
1517+
Py_DECREF(kwonly_name);
1518+
VISIT_QUIT(st, 0);
1519+
}
1520+
Py_DECREF(kwonly_name);
1521+
}
1522+
VISIT_SEQ(st, typeparam, s->v.AsyncFunctionDef.typeparams);
1523+
}
14911524
if (!symtable_visit_annotations(st, s, s->v.AsyncFunctionDef.args,
14921525
s->v.AsyncFunctionDef.returns))
14931526
VISIT_QUIT(st, 0);
1494-
if (s->v.AsyncFunctionDef.decorator_list)
1495-
VISIT_SEQ(st, expr, s->v.AsyncFunctionDef.decorator_list);
14961527
if (!symtable_enter_block(st, s->v.AsyncFunctionDef.name,
14971528
FunctionBlock, (void *)s,
14981529
s->lineno, s->col_offset,
@@ -1503,6 +1534,10 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
15031534
VISIT_SEQ(st, stmt, s->v.AsyncFunctionDef.body);
15041535
if (!symtable_exit_block(st))
15051536
VISIT_QUIT(st, 0);
1537+
if (s->v.AsyncFunctionDef.typeparams) {
1538+
if (!symtable_exit_block(st))
1539+
VISIT_QUIT(st, 0);
1540+
}
15061541
break;
15071542
case AsyncWith_kind:
15081543
VISIT_SEQ(st, withitem, s->v.AsyncWith.items);

0 commit comments

Comments
 (0)
0