gh-104656: Rename typeparams AST node to type_params (#104657)

This commit is contained in:
Jelle Zijlstra 2023-05-21 21:25:09 -07:00 committed by GitHub
parent ef5d00a592
commit a5f244d627
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 290 additions and 287 deletions

View file

@ -2113,15 +2113,15 @@ wrap_in_stopiteration_handler(struct compiler *c)
}
static int
compiler_type_params(struct compiler *c, asdl_typeparam_seq *typeparams)
compiler_type_params(struct compiler *c, asdl_type_param_seq *type_params)
{
if (!typeparams) {
if (!type_params) {
return SUCCESS;
}
Py_ssize_t n = asdl_seq_LEN(typeparams);
Py_ssize_t n = asdl_seq_LEN(type_params);
for (Py_ssize_t i = 0; i < n; i++) {
typeparam_ty typeparam = asdl_seq_GET(typeparams, i);
type_param_ty typeparam = asdl_seq_GET(type_params, i);
location loc = LOC(typeparam);
switch(typeparam->kind) {
case TypeVar_kind:
@ -2170,7 +2170,7 @@ compiler_type_params(struct compiler *c, asdl_typeparam_seq *typeparams)
break;
}
}
ADDOP_I(c, LOC(asdl_seq_GET(typeparams, 0)), BUILD_TUPLE, n);
ADDOP_I(c, LOC(asdl_seq_GET(type_params, 0)), BUILD_TUPLE, n);
return SUCCESS;
}
@ -2248,7 +2248,7 @@ compiler_function(struct compiler *c, stmt_ty s, int is_async)
expr_ty returns;
identifier name;
asdl_expr_seq *decos;
asdl_typeparam_seq *typeparams;
asdl_type_param_seq *type_params;
Py_ssize_t funcflags;
int annotations;
int firstlineno;
@ -2260,7 +2260,7 @@ compiler_function(struct compiler *c, stmt_ty s, int is_async)
returns = s->v.AsyncFunctionDef.returns;
decos = s->v.AsyncFunctionDef.decorator_list;
name = s->v.AsyncFunctionDef.name;
typeparams = s->v.AsyncFunctionDef.typeparams;
type_params = s->v.AsyncFunctionDef.type_params;
} else {
assert(s->kind == FunctionDef_kind);
@ -2268,7 +2268,7 @@ compiler_function(struct compiler *c, stmt_ty s, int is_async)
returns = s->v.FunctionDef.returns;
decos = s->v.FunctionDef.decorator_list;
name = s->v.FunctionDef.name;
typeparams = s->v.FunctionDef.typeparams;
type_params = s->v.FunctionDef.type_params;
}
RETURN_IF_ERROR(compiler_check_debug_args(c, args));
@ -2281,7 +2281,7 @@ compiler_function(struct compiler *c, stmt_ty s, int is_async)
location loc = LOC(s);
int is_generic = asdl_seq_LEN(typeparams) > 0;
int is_generic = asdl_seq_LEN(type_params) > 0;
if (is_generic) {
// Used by the CALL to the type parameters function.
@ -2305,17 +2305,17 @@ compiler_function(struct compiler *c, stmt_ty s, int is_async)
if (num_typeparam_args == 2) {
ADDOP_I(c, loc, SWAP, 2);
}
PyObject *typeparams_name = PyUnicode_FromFormat("<generic parameters of %U>", name);
if (!typeparams_name) {
PyObject *type_params_name = PyUnicode_FromFormat("<generic parameters of %U>", name);
if (!type_params_name) {
return ERROR;
}
if (compiler_enter_scope(c, typeparams_name, COMPILER_SCOPE_TYPEPARAMS,
(void *)typeparams, firstlineno) == -1) {
Py_DECREF(typeparams_name);
if (compiler_enter_scope(c, type_params_name, COMPILER_SCOPE_TYPEPARAMS,
(void *)type_params, firstlineno) == -1) {
Py_DECREF(type_params_name);
return ERROR;
}
Py_DECREF(typeparams_name);
RETURN_IF_ERROR_IN_SCOPE(c, compiler_type_params(c, typeparams));
Py_DECREF(type_params_name);
RETURN_IF_ERROR_IN_SCOPE(c, compiler_type_params(c, type_params));
if ((funcflags & 0x01) || (funcflags & 0x02)) {
RETURN_IF_ERROR_IN_SCOPE(c, codegen_addop_i(INSTR_SEQUENCE(c), LOAD_FAST, 0, loc));
}
@ -2416,8 +2416,8 @@ compiler_class_body(struct compiler *c, stmt_ty s, int firstlineno)
compiler_exit_scope(c);
return ERROR;
}
asdl_typeparam_seq *typeparams = s->v.ClassDef.typeparams;
if (asdl_seq_LEN(typeparams) > 0) {
asdl_type_param_seq *type_params = s->v.ClassDef.type_params;
if (asdl_seq_LEN(type_params) > 0) {
if (!compiler_set_type_params_in_class(c, loc)) {
compiler_exit_scope(c);
return ERROR;
@ -2519,23 +2519,23 @@ compiler_class(struct compiler *c, stmt_ty s)
}
location loc = LOC(s);
asdl_typeparam_seq *typeparams = s->v.ClassDef.typeparams;
int is_generic = asdl_seq_LEN(typeparams) > 0;
asdl_type_param_seq *type_params = s->v.ClassDef.type_params;
int is_generic = asdl_seq_LEN(type_params) > 0;
if (is_generic) {
Py_XSETREF(c->u->u_private, Py_NewRef(s->v.ClassDef.name));
ADDOP(c, loc, PUSH_NULL);
PyObject *typeparams_name = PyUnicode_FromFormat("<generic parameters of %U>",
PyObject *type_params_name = PyUnicode_FromFormat("<generic parameters of %U>",
s->v.ClassDef.name);
if (!typeparams_name) {
if (!type_params_name) {
return ERROR;
}
if (compiler_enter_scope(c, typeparams_name, COMPILER_SCOPE_TYPEPARAMS,
(void *)typeparams, firstlineno) == -1) {
Py_DECREF(typeparams_name);
if (compiler_enter_scope(c, type_params_name, COMPILER_SCOPE_TYPEPARAMS,
(void *)type_params, firstlineno) == -1) {
Py_DECREF(type_params_name);
return ERROR;
}
Py_DECREF(typeparams_name);
RETURN_IF_ERROR_IN_SCOPE(c, compiler_type_params(c, typeparams));
Py_DECREF(type_params_name);
RETURN_IF_ERROR_IN_SCOPE(c, compiler_type_params(c, type_params));
_Py_DECLARE_STR(type_params, ".type_params");
RETURN_IF_ERROR_IN_SCOPE(c, compiler_nameop(c, loc, &_Py_STR(type_params), Store));
}
@ -2637,26 +2637,26 @@ static int
compiler_typealias(struct compiler *c, stmt_ty s)
{
location loc = LOC(s);
asdl_typeparam_seq *typeparams = s->v.TypeAlias.typeparams;
int is_generic = asdl_seq_LEN(typeparams) > 0;
asdl_type_param_seq *type_params = s->v.TypeAlias.type_params;
int is_generic = asdl_seq_LEN(type_params) > 0;
PyObject *name = s->v.TypeAlias.name->v.Name.id;
if (is_generic) {
ADDOP(c, loc, PUSH_NULL);
PyObject *typeparams_name = PyUnicode_FromFormat("<generic parameters of %U>",
PyObject *type_params_name = PyUnicode_FromFormat("<generic parameters of %U>",
name);
if (!typeparams_name) {
if (!type_params_name) {
return ERROR;
}
if (compiler_enter_scope(c, typeparams_name, COMPILER_SCOPE_TYPEPARAMS,
(void *)typeparams, loc.lineno) == -1) {
Py_DECREF(typeparams_name);
if (compiler_enter_scope(c, type_params_name, COMPILER_SCOPE_TYPEPARAMS,
(void *)type_params, loc.lineno) == -1) {
Py_DECREF(type_params_name);
return ERROR;
}
Py_DECREF(typeparams_name);
Py_DECREF(type_params_name);
RETURN_IF_ERROR_IN_SCOPE(
c, compiler_addop_load_const(c->c_const_cache, c->u, loc, name)
);
RETURN_IF_ERROR_IN_SCOPE(c, compiler_type_params(c, typeparams));
RETURN_IF_ERROR_IN_SCOPE(c, compiler_type_params(c, type_params));
}
else {
ADDOP_LOAD_CONST(c, loc, name);