mirror of
https://github.com/python/cpython.git
synced 2025-07-09 20:35:26 +00:00
gh-119180: Add evaluate functions for type params and type aliases (#122212)
This commit is contained in:
parent
cbac8a3888
commit
ae192262ad
11 changed files with 385 additions and 159 deletions
|
@ -1978,8 +1978,9 @@ compiler_type_param_bound_or_default(struct compiler *c, expr_ty e,
|
|||
identifier name, void *key,
|
||||
bool allow_starred)
|
||||
{
|
||||
if (compiler_enter_scope(c, name, COMPILER_SCOPE_ANNOTATIONS,
|
||||
key, e->lineno, NULL) == -1) {
|
||||
PyObject *defaults = PyTuple_Pack(1, _PyLong_GetOne());
|
||||
ADDOP_LOAD_CONST_NEW(c, LOC(e), defaults);
|
||||
if (compiler_setup_annotations_scope(c, LOC(e), key, name) == -1) {
|
||||
return ERROR;
|
||||
}
|
||||
if (allow_starred && e->kind == Starred_kind) {
|
||||
|
@ -1995,7 +1996,7 @@ compiler_type_param_bound_or_default(struct compiler *c, expr_ty e,
|
|||
if (co == NULL) {
|
||||
return ERROR;
|
||||
}
|
||||
if (compiler_make_closure(c, LOC(e), co, 0) < 0) {
|
||||
if (compiler_make_closure(c, LOC(e), co, MAKE_FUNCTION_DEFAULTS) < 0) {
|
||||
Py_DECREF(co);
|
||||
return ERROR;
|
||||
}
|
||||
|
@ -2566,8 +2567,10 @@ compiler_typealias_body(struct compiler *c, stmt_ty s)
|
|||
{
|
||||
location loc = LOC(s);
|
||||
PyObject *name = s->v.TypeAlias.name->v.Name.id;
|
||||
PyObject *defaults = PyTuple_Pack(1, _PyLong_GetOne());
|
||||
ADDOP_LOAD_CONST_NEW(c, loc, defaults);
|
||||
RETURN_IF_ERROR(
|
||||
compiler_enter_scope(c, name, COMPILER_SCOPE_FUNCTION, s, loc.lineno, NULL));
|
||||
compiler_setup_annotations_scope(c, LOC(s), s, name));
|
||||
/* Make None the first constant, so the evaluate function can't have a
|
||||
docstring. */
|
||||
RETURN_IF_ERROR(compiler_add_const(c, Py_None));
|
||||
|
@ -2578,7 +2581,7 @@ compiler_typealias_body(struct compiler *c, stmt_ty s)
|
|||
if (co == NULL) {
|
||||
return ERROR;
|
||||
}
|
||||
if (compiler_make_closure(c, loc, co, 0) < 0) {
|
||||
if (compiler_make_closure(c, loc, co, MAKE_FUNCTION_DEFAULTS) < 0) {
|
||||
Py_DECREF(co);
|
||||
return ERROR;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue