diff options
author | Jelle Zijlstra <jelle.zijlstra@gmail.com> | 2023-05-22 04:25:09 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-22 04:25:09 (GMT) |
commit | a5f244d627a6815cf2d8ccec836b9b52eb3e8de2 (patch) | |
tree | 55b68f8a6f9366132742fb45bd93199065f9e720 /Python | |
parent | ef5d00a59207a63c6d5ae0d5d44054847d1bf3b5 (diff) | |
download | cpython-a5f244d627a6815cf2d8ccec836b9b52eb3e8de2.zip cpython-a5f244d627a6815cf2d8ccec836b9b52eb3e8de2.tar.gz cpython-a5f244d627a6815cf2d8ccec836b9b52eb3e8de2.tar.bz2 |
gh-104656: Rename typeparams AST node to type_params (#104657)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/Python-ast.c | 252 | ||||
-rw-r--r-- | Python/ast.c | 18 | ||||
-rw-r--r-- | Python/ast_opt.c | 12 | ||||
-rw-r--r-- | Python/compile.c | 72 | ||||
-rw-r--r-- | Python/symtable.c | 86 |
5 files changed, 221 insertions, 219 deletions
diff --git a/Python/Python-ast.c b/Python/Python-ast.c index d62cccb..87906d9 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -261,8 +261,8 @@ void _PyAST_Fini(PyInterpreterState *interp) Py_CLEAR(state->type_comment); Py_CLEAR(state->type_ignore_type); Py_CLEAR(state->type_ignores); - Py_CLEAR(state->typeparam_type); - Py_CLEAR(state->typeparams); + Py_CLEAR(state->type_param_type); + Py_CLEAR(state->type_params); Py_CLEAR(state->unaryop_type); Py_CLEAR(state->upper); Py_CLEAR(state->value); @@ -362,7 +362,7 @@ static int init_identifiers(struct ast_state *state) if ((state->type = PyUnicode_InternFromString("type")) == NULL) return 0; if ((state->type_comment = PyUnicode_InternFromString("type_comment")) == NULL) return 0; if ((state->type_ignores = PyUnicode_InternFromString("type_ignores")) == NULL) return 0; - if ((state->typeparams = PyUnicode_InternFromString("typeparams")) == NULL) return 0; + if ((state->type_params = PyUnicode_InternFromString("type_params")) == NULL) return 0; if ((state->upper = PyUnicode_InternFromString("upper")) == NULL) return 0; if ((state->value = PyUnicode_InternFromString("value")) == NULL) return 0; if ((state->values = PyUnicode_InternFromString("values")) == NULL) return 0; @@ -383,7 +383,7 @@ GENERATE_ASDL_SEQ_CONSTRUCTOR(withitem, withitem_ty) GENERATE_ASDL_SEQ_CONSTRUCTOR(match_case, match_case_ty) GENERATE_ASDL_SEQ_CONSTRUCTOR(pattern, pattern_ty) GENERATE_ASDL_SEQ_CONSTRUCTOR(type_ignore, type_ignore_ty) -GENERATE_ASDL_SEQ_CONSTRUCTOR(typeparam, typeparam_ty) +GENERATE_ASDL_SEQ_CONSTRUCTOR(type_param, type_param_ty) static PyObject* ast2obj_mod(struct ast_state *state, void*); static const char * const Module_fields[]={ @@ -409,7 +409,7 @@ static const char * const stmt_attributes[] = { static PyObject* ast2obj_stmt(struct ast_state *state, void*); static const char * const FunctionDef_fields[]={ "name", - "typeparams", + "type_params", "args", "body", "decorator_list", @@ -418,7 +418,7 @@ static const char * const FunctionDef_fields[]={ }; static const char * const AsyncFunctionDef_fields[]={ "name", - "typeparams", + "type_params", "args", "body", "decorator_list", @@ -427,7 +427,7 @@ static const char * const AsyncFunctionDef_fields[]={ }; static const char * const ClassDef_fields[]={ "name", - "typeparams", + "type_params", "bases", "keywords", "body", @@ -446,7 +446,7 @@ static const char * const Assign_fields[]={ }; static const char * const TypeAlias_fields[]={ "name", - "typeparams", + "type_params", "value", }; static const char * const AugAssign_fields[]={ @@ -775,13 +775,13 @@ static const char * const TypeIgnore_fields[]={ "lineno", "tag", }; -static const char * const typeparam_attributes[] = { +static const char * const type_param_attributes[] = { "lineno", "col_offset", "end_lineno", "end_col_offset", }; -static PyObject* ast2obj_typeparam(struct ast_state *state, void*); +static PyObject* ast2obj_type_param(struct ast_state *state, void*); static const char * const TypeVar_fields[]={ "name", "bound", @@ -1169,13 +1169,13 @@ init_types(struct ast_state *state) "FunctionType(expr* argtypes, expr returns)"); if (!state->FunctionType_type) return 0; state->stmt_type = make_type(state, "stmt", state->AST_type, NULL, 0, - "stmt = FunctionDef(identifier name, typeparam* typeparams, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n" - " | AsyncFunctionDef(identifier name, typeparam* typeparams, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n" - " | ClassDef(identifier name, typeparam* typeparams, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)\n" + "stmt = FunctionDef(identifier name, type_param* type_params, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n" + " | AsyncFunctionDef(identifier name, type_param* type_params, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n" + " | ClassDef(identifier name, type_param* type_params, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)\n" " | Return(expr? value)\n" " | Delete(expr* targets)\n" " | Assign(expr* targets, expr value, string? type_comment)\n" - " | TypeAlias(expr name, typeparam* typeparams, expr value)\n" + " | TypeAlias(expr name, type_param* type_params, expr value)\n" " | AugAssign(expr target, operator op, expr value)\n" " | AnnAssign(expr target, expr annotation, expr? value, int simple)\n" " | For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n" @@ -1206,7 +1206,7 @@ init_types(struct ast_state *state) return 0; state->FunctionDef_type = make_type(state, "FunctionDef", state->stmt_type, FunctionDef_fields, 7, - "FunctionDef(identifier name, typeparam* typeparams, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)"); + "FunctionDef(identifier name, type_param* type_params, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)"); if (!state->FunctionDef_type) return 0; if (PyObject_SetAttr(state->FunctionDef_type, state->returns, Py_None) == -1) @@ -1217,7 +1217,7 @@ init_types(struct ast_state *state) state->AsyncFunctionDef_type = make_type(state, "AsyncFunctionDef", state->stmt_type, AsyncFunctionDef_fields, 7, - "AsyncFunctionDef(identifier name, typeparam* typeparams, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)"); + "AsyncFunctionDef(identifier name, type_param* type_params, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)"); if (!state->AsyncFunctionDef_type) return 0; if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->returns, Py_None) == -1) @@ -1227,7 +1227,7 @@ init_types(struct ast_state *state) return 0; state->ClassDef_type = make_type(state, "ClassDef", state->stmt_type, ClassDef_fields, 6, - "ClassDef(identifier name, typeparam* typeparams, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)"); + "ClassDef(identifier name, type_param* type_params, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)"); if (!state->ClassDef_type) return 0; state->Return_type = make_type(state, "Return", state->stmt_type, Return_fields, 1, @@ -1248,7 +1248,7 @@ init_types(struct ast_state *state) return 0; state->TypeAlias_type = make_type(state, "TypeAlias", state->stmt_type, TypeAlias_fields, 3, - "TypeAlias(expr name, typeparam* typeparams, expr value)"); + "TypeAlias(expr name, type_param* type_params, expr value)"); if (!state->TypeAlias_type) return 0; state->AugAssign_type = make_type(state, "AugAssign", state->stmt_type, AugAssign_fields, 3, @@ -1894,33 +1894,33 @@ init_types(struct ast_state *state) TypeIgnore_fields, 2, "TypeIgnore(int lineno, string tag)"); if (!state->TypeIgnore_type) return 0; - state->typeparam_type = make_type(state, "typeparam", state->AST_type, - NULL, 0, - "typeparam = TypeVar(identifier name, expr? bound)\n" - " | ParamSpec(identifier name)\n" - " | TypeVarTuple(identifier name)"); - if (!state->typeparam_type) return 0; - if (!add_attributes(state, state->typeparam_type, typeparam_attributes, 4)) - return 0; - if (PyObject_SetAttr(state->typeparam_type, state->end_lineno, Py_None) == + state->type_param_type = make_type(state, "type_param", state->AST_type, + NULL, 0, + "type_param = TypeVar(identifier name, expr? bound)\n" + " | ParamSpec(identifier name)\n" + " | TypeVarTuple(identifier name)"); + if (!state->type_param_type) return 0; + if (!add_attributes(state, state->type_param_type, type_param_attributes, + 4)) return 0; + if (PyObject_SetAttr(state->type_param_type, state->end_lineno, Py_None) == -1) return 0; - if (PyObject_SetAttr(state->typeparam_type, state->end_col_offset, Py_None) - == -1) + if (PyObject_SetAttr(state->type_param_type, state->end_col_offset, + Py_None) == -1) return 0; - state->TypeVar_type = make_type(state, "TypeVar", state->typeparam_type, + state->TypeVar_type = make_type(state, "TypeVar", state->type_param_type, TypeVar_fields, 2, "TypeVar(identifier name, expr? bound)"); if (!state->TypeVar_type) return 0; if (PyObject_SetAttr(state->TypeVar_type, state->bound, Py_None) == -1) return 0; state->ParamSpec_type = make_type(state, "ParamSpec", - state->typeparam_type, ParamSpec_fields, + state->type_param_type, ParamSpec_fields, 1, "ParamSpec(identifier name)"); if (!state->ParamSpec_type) return 0; state->TypeVarTuple_type = make_type(state, "TypeVarTuple", - state->typeparam_type, + state->type_param_type, TypeVarTuple_fields, 1, "TypeVarTuple(identifier name)"); if (!state->TypeVarTuple_type) return 0; @@ -1967,8 +1967,8 @@ static int obj2ast_pattern(struct ast_state *state, PyObject* obj, pattern_ty* out, PyArena* arena); static int obj2ast_type_ignore(struct ast_state *state, PyObject* obj, type_ignore_ty* out, PyArena* arena); -static int obj2ast_typeparam(struct ast_state *state, PyObject* obj, - typeparam_ty* out, PyArena* arena); +static int obj2ast_type_param(struct ast_state *state, PyObject* obj, + type_param_ty* out, PyArena* arena); mod_ty _PyAST_Module(asdl_stmt_seq * body, asdl_type_ignore_seq * type_ignores, @@ -2032,7 +2032,7 @@ _PyAST_FunctionType(asdl_expr_seq * argtypes, expr_ty returns, PyArena *arena) } stmt_ty -_PyAST_FunctionDef(identifier name, asdl_typeparam_seq * typeparams, +_PyAST_FunctionDef(identifier name, asdl_type_param_seq * type_params, arguments_ty args, asdl_stmt_seq * body, asdl_expr_seq * decorator_list, expr_ty returns, string type_comment, int lineno, int col_offset, int end_lineno, int end_col_offset, @@ -2054,7 +2054,7 @@ _PyAST_FunctionDef(identifier name, asdl_typeparam_seq * typeparams, return NULL; p->kind = FunctionDef_kind; p->v.FunctionDef.name = name; - p->v.FunctionDef.typeparams = typeparams; + p->v.FunctionDef.type_params = type_params; p->v.FunctionDef.args = args; p->v.FunctionDef.body = body; p->v.FunctionDef.decorator_list = decorator_list; @@ -2068,7 +2068,7 @@ _PyAST_FunctionDef(identifier name, asdl_typeparam_seq * typeparams, } stmt_ty -_PyAST_AsyncFunctionDef(identifier name, asdl_typeparam_seq * typeparams, +_PyAST_AsyncFunctionDef(identifier name, asdl_type_param_seq * type_params, arguments_ty args, asdl_stmt_seq * body, asdl_expr_seq * decorator_list, expr_ty returns, string type_comment, int lineno, int col_offset, int end_lineno, int @@ -2090,7 +2090,7 @@ _PyAST_AsyncFunctionDef(identifier name, asdl_typeparam_seq * typeparams, return NULL; p->kind = AsyncFunctionDef_kind; p->v.AsyncFunctionDef.name = name; - p->v.AsyncFunctionDef.typeparams = typeparams; + p->v.AsyncFunctionDef.type_params = type_params; p->v.AsyncFunctionDef.args = args; p->v.AsyncFunctionDef.body = body; p->v.AsyncFunctionDef.decorator_list = decorator_list; @@ -2104,10 +2104,11 @@ _PyAST_AsyncFunctionDef(identifier name, asdl_typeparam_seq * typeparams, } stmt_ty -_PyAST_ClassDef(identifier name, asdl_typeparam_seq * typeparams, asdl_expr_seq - * bases, asdl_keyword_seq * keywords, asdl_stmt_seq * body, - asdl_expr_seq * decorator_list, int lineno, int col_offset, int - end_lineno, int end_col_offset, PyArena *arena) +_PyAST_ClassDef(identifier name, asdl_type_param_seq * type_params, + asdl_expr_seq * bases, asdl_keyword_seq * keywords, + asdl_stmt_seq * body, asdl_expr_seq * decorator_list, int + lineno, int col_offset, int end_lineno, int end_col_offset, + PyArena *arena) { stmt_ty p; if (!name) { @@ -2120,7 +2121,7 @@ _PyAST_ClassDef(identifier name, asdl_typeparam_seq * typeparams, asdl_expr_seq return NULL; p->kind = ClassDef_kind; p->v.ClassDef.name = name; - p->v.ClassDef.typeparams = typeparams; + p->v.ClassDef.type_params = type_params; p->v.ClassDef.bases = bases; p->v.ClassDef.keywords = keywords; p->v.ClassDef.body = body; @@ -2192,8 +2193,8 @@ _PyAST_Assign(asdl_expr_seq * targets, expr_ty value, string type_comment, int } stmt_ty -_PyAST_TypeAlias(expr_ty name, asdl_typeparam_seq * typeparams, expr_ty value, - int lineno, int col_offset, int end_lineno, int +_PyAST_TypeAlias(expr_ty name, asdl_type_param_seq * type_params, expr_ty + value, int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena *arena) { stmt_ty p; @@ -2212,7 +2213,7 @@ _PyAST_TypeAlias(expr_ty name, asdl_typeparam_seq * typeparams, expr_ty value, return NULL; p->kind = TypeAlias_kind; p->v.TypeAlias.name = name; - p->v.TypeAlias.typeparams = typeparams; + p->v.TypeAlias.type_params = type_params; p->v.TypeAlias.value = value; p->lineno = lineno; p->col_offset = col_offset; @@ -3713,17 +3714,17 @@ _PyAST_TypeIgnore(int lineno, string tag, PyArena *arena) return p; } -typeparam_ty +type_param_ty _PyAST_TypeVar(identifier name, expr_ty bound, int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena *arena) { - typeparam_ty p; + type_param_ty p; if (!name) { PyErr_SetString(PyExc_ValueError, "field 'name' is required for TypeVar"); return NULL; } - p = (typeparam_ty)_PyArena_Malloc(arena, sizeof(*p)); + p = (type_param_ty)_PyArena_Malloc(arena, sizeof(*p)); if (!p) return NULL; p->kind = TypeVar_kind; @@ -3736,17 +3737,17 @@ _PyAST_TypeVar(identifier name, expr_ty bound, int lineno, int col_offset, int return p; } -typeparam_ty +type_param_ty _PyAST_ParamSpec(identifier name, int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena *arena) { - typeparam_ty p; + type_param_ty p; if (!name) { PyErr_SetString(PyExc_ValueError, "field 'name' is required for ParamSpec"); return NULL; } - p = (typeparam_ty)_PyArena_Malloc(arena, sizeof(*p)); + p = (type_param_ty)_PyArena_Malloc(arena, sizeof(*p)); if (!p) return NULL; p->kind = ParamSpec_kind; @@ -3758,17 +3759,17 @@ _PyAST_ParamSpec(identifier name, int lineno, int col_offset, int end_lineno, return p; } -typeparam_ty +type_param_ty _PyAST_TypeVarTuple(identifier name, int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena *arena) { - typeparam_ty p; + type_param_ty p; if (!name) { PyErr_SetString(PyExc_ValueError, "field 'name' is required for TypeVarTuple"); return NULL; } - p = (typeparam_ty)_PyArena_Malloc(arena, sizeof(*p)); + p = (type_param_ty)_PyArena_Malloc(arena, sizeof(*p)); if (!p) return NULL; p->kind = TypeVarTuple_kind; @@ -3882,10 +3883,10 @@ ast2obj_stmt(struct ast_state *state, void* _o) if (PyObject_SetAttr(result, state->name, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(state, (asdl_seq*)o->v.FunctionDef.typeparams, - ast2obj_typeparam); + value = ast2obj_list(state, (asdl_seq*)o->v.FunctionDef.type_params, + ast2obj_type_param); if (!value) goto failed; - if (PyObject_SetAttr(result, state->typeparams, value) == -1) + if (PyObject_SetAttr(result, state->type_params, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_arguments(state, o->v.FunctionDef.args); @@ -3926,10 +3927,10 @@ ast2obj_stmt(struct ast_state *state, void* _o) goto failed; Py_DECREF(value); value = ast2obj_list(state, - (asdl_seq*)o->v.AsyncFunctionDef.typeparams, - ast2obj_typeparam); + (asdl_seq*)o->v.AsyncFunctionDef.type_params, + ast2obj_type_param); if (!value) goto failed; - if (PyObject_SetAttr(result, state->typeparams, value) == -1) + if (PyObject_SetAttr(result, state->type_params, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_arguments(state, o->v.AsyncFunctionDef.args); @@ -3970,10 +3971,10 @@ ast2obj_stmt(struct ast_state *state, void* _o) if (PyObject_SetAttr(result, state->name, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.typeparams, - ast2obj_typeparam); + value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.type_params, + ast2obj_type_param); if (!value) goto failed; - if (PyObject_SetAttr(result, state->typeparams, value) == -1) + if (PyObject_SetAttr(result, state->type_params, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.bases, @@ -4052,10 +4053,10 @@ ast2obj_stmt(struct ast_state *state, void* _o) if (PyObject_SetAttr(result, state->name, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(state, (asdl_seq*)o->v.TypeAlias.typeparams, - ast2obj_typeparam); + value = ast2obj_list(state, (asdl_seq*)o->v.TypeAlias.type_params, + ast2obj_type_param); if (!value) goto failed; - if (PyObject_SetAttr(result, state->typeparams, value) == -1) + if (PyObject_SetAttr(result, state->type_params, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(state, o->v.TypeAlias.value); @@ -5656,9 +5657,9 @@ failed: } PyObject* -ast2obj_typeparam(struct ast_state *state, void* _o) +ast2obj_type_param(struct ast_state *state, void* _o) { - typeparam_ty o = (typeparam_ty)_o; + type_param_ty o = (type_param_ty)_o; PyObject *result = NULL, *value = NULL; PyTypeObject *tp; if (!o) { @@ -6074,7 +6075,7 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena* } if (isinstance) { identifier name; - asdl_typeparam_seq* typeparams; + asdl_type_param_seq* type_params; arguments_ty args; asdl_stmt_seq* body; asdl_expr_seq* decorator_list; @@ -6098,11 +6099,11 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena* if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, state->typeparams, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->type_params, &tmp) < 0) { return 1; } if (tmp == NULL) { - PyErr_SetString(PyExc_TypeError, "required field \"typeparams\" missing from FunctionDef"); + PyErr_SetString(PyExc_TypeError, "required field \"type_params\" missing from FunctionDef"); return 1; } else { @@ -6110,27 +6111,27 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena* Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "FunctionDef field \"typeparams\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "FunctionDef field \"type_params\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - typeparams = _Py_asdl_typeparam_seq_new(len, arena); - if (typeparams == NULL) goto failed; + type_params = _Py_asdl_type_param_seq_new(len, arena); + if (type_params == NULL) goto failed; for (i = 0; i < len; i++) { - typeparam_ty val; + type_param_ty val; PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i)); if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) { goto failed; } - res = obj2ast_typeparam(state, tmp2, &val, arena); + res = obj2ast_type_param(state, tmp2, &val, arena); _Py_LeaveRecursiveCall(); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { - PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"typeparams\" changed size during iteration"); + PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"type_params\" changed size during iteration"); goto failed; } - asdl_seq_SET(typeparams, i, val); + asdl_seq_SET(type_params, i, val); } Py_CLEAR(tmp); } @@ -6257,9 +6258,10 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena* if (res != 0) goto failed; Py_CLEAR(tmp); } - *out = _PyAST_FunctionDef(name, typeparams, args, body, decorator_list, - returns, type_comment, lineno, col_offset, - end_lineno, end_col_offset, arena); + *out = _PyAST_FunctionDef(name, type_params, args, body, + decorator_list, returns, type_comment, + lineno, col_offset, end_lineno, + end_col_offset, arena); if (*out == NULL) goto failed; return 0; } @@ -6270,7 +6272,7 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena* } if (isinstance) { identifier name; - asdl_typeparam_seq* typeparams; + asdl_type_param_seq* type_params; arguments_ty args; asdl_stmt_seq* body; asdl_expr_seq* decorator_list; @@ -6294,11 +6296,11 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena* if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, state->typeparams, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->type_params, &tmp) < 0) { return 1; } if (tmp == NULL) { - PyErr_SetString(PyExc_TypeError, "required field \"typeparams\" missing from AsyncFunctionDef"); + PyErr_SetString(PyExc_TypeError, "required field \"type_params\" missing from AsyncFunctionDef"); return 1; } else { @@ -6306,27 +6308,27 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena* Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"typeparams\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"type_params\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - typeparams = _Py_asdl_typeparam_seq_new(len, arena); - if (typeparams == NULL) goto failed; + type_params = _Py_asdl_type_param_seq_new(len, arena); + if (type_params == NULL) goto failed; for (i = 0; i < len; i++) { - typeparam_ty val; + type_param_ty val; PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i)); if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) { goto failed; } - res = obj2ast_typeparam(state, tmp2, &val, arena); + res = obj2ast_type_param(state, tmp2, &val, arena); _Py_LeaveRecursiveCall(); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { - PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"typeparams\" changed size during iteration"); + PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"type_params\" changed size during iteration"); goto failed; } - asdl_seq_SET(typeparams, i, val); + asdl_seq_SET(type_params, i, val); } Py_CLEAR(tmp); } @@ -6453,7 +6455,7 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena* if (res != 0) goto failed; Py_CLEAR(tmp); } - *out = _PyAST_AsyncFunctionDef(name, typeparams, args, body, + *out = _PyAST_AsyncFunctionDef(name, type_params, args, body, decorator_list, returns, type_comment, lineno, col_offset, end_lineno, end_col_offset, arena); @@ -6467,7 +6469,7 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena* } if (isinstance) { identifier name; - asdl_typeparam_seq* typeparams; + asdl_type_param_seq* type_params; asdl_expr_seq* bases; asdl_keyword_seq* keywords; asdl_stmt_seq* body; @@ -6490,11 +6492,11 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena* if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, state->typeparams, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->type_params, &tmp) < 0) { return 1; } if (tmp == NULL) { - PyErr_SetString(PyExc_TypeError, "required field \"typeparams\" missing from ClassDef"); + PyErr_SetString(PyExc_TypeError, "required field \"type_params\" missing from ClassDef"); return 1; } else { @@ -6502,27 +6504,27 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena* Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "ClassDef field \"typeparams\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "ClassDef field \"type_params\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - typeparams = _Py_asdl_typeparam_seq_new(len, arena); - if (typeparams == NULL) goto failed; + type_params = _Py_asdl_type_param_seq_new(len, arena); + if (type_params == NULL) goto failed; for (i = 0; i < len; i++) { - typeparam_ty val; + type_param_ty val; PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i)); if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) { goto failed; } - res = obj2ast_typeparam(state, tmp2, &val, arena); + res = obj2ast_type_param(state, tmp2, &val, arena); _Py_LeaveRecursiveCall(); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { - PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"typeparams\" changed size during iteration"); + PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"type_params\" changed size during iteration"); goto failed; } - asdl_seq_SET(typeparams, i, val); + asdl_seq_SET(type_params, i, val); } Py_CLEAR(tmp); } @@ -6670,7 +6672,7 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena* } Py_CLEAR(tmp); } - *out = _PyAST_ClassDef(name, typeparams, bases, keywords, body, + *out = _PyAST_ClassDef(name, type_params, bases, keywords, body, decorator_list, lineno, col_offset, end_lineno, end_col_offset, arena); if (*out == NULL) goto failed; @@ -6847,7 +6849,7 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena* } if (isinstance) { expr_ty name; - asdl_typeparam_seq* typeparams; + asdl_type_param_seq* type_params; expr_ty value; if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) { @@ -6867,11 +6869,11 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena* if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, state->typeparams, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->type_params, &tmp) < 0) { return 1; } if (tmp == NULL) { - PyErr_SetString(PyExc_TypeError, "required field \"typeparams\" missing from TypeAlias"); + PyErr_SetString(PyExc_TypeError, "required field \"type_params\" missing from TypeAlias"); return 1; } else { @@ -6879,27 +6881,27 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena* Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "TypeAlias field \"typeparams\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); + PyErr_Format(PyExc_TypeError, "TypeAlias field \"type_params\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); goto failed; } len = PyList_GET_SIZE(tmp); - typeparams = _Py_asdl_typeparam_seq_new(len, arena); - if (typeparams == NULL) goto failed; + type_params = _Py_asdl_type_param_seq_new(len, arena); + if (type_params == NULL) goto failed; for (i = 0; i < len; i++) { - typeparam_ty val; + type_param_ty val; PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i)); if (_Py_EnterRecursiveCall(" while traversing 'TypeAlias' node")) { goto failed; } - res = obj2ast_typeparam(state, tmp2, &val, arena); + res = obj2ast_type_param(state, tmp2, &val, arena); _Py_LeaveRecursiveCall(); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { - PyErr_SetString(PyExc_RuntimeError, "TypeAlias field \"typeparams\" changed size during iteration"); + PyErr_SetString(PyExc_RuntimeError, "TypeAlias field \"type_params\" changed size during iteration"); goto failed; } - asdl_seq_SET(typeparams, i, val); + asdl_seq_SET(type_params, i, val); } Py_CLEAR(tmp); } @@ -6920,7 +6922,7 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena* if (res != 0) goto failed; Py_CLEAR(tmp); } - *out = _PyAST_TypeAlias(name, typeparams, value, lineno, col_offset, + *out = _PyAST_TypeAlias(name, type_params, value, lineno, col_offset, end_lineno, end_col_offset, arena); if (*out == NULL) goto failed; return 0; @@ -12293,8 +12295,8 @@ obj2ast_type_ignore(struct ast_state *state, PyObject* obj, type_ignore_ty* } int -obj2ast_typeparam(struct ast_state *state, PyObject* obj, typeparam_ty* out, - PyArena* arena) +obj2ast_type_param(struct ast_state *state, PyObject* obj, type_param_ty* out, + PyArena* arena) { int isinstance; @@ -12313,12 +12315,12 @@ obj2ast_typeparam(struct ast_state *state, PyObject* obj, typeparam_ty* out, return 1; } if (tmp == NULL) { - PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from typeparam"); + PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from type_param"); return 1; } else { int res; - if (_Py_EnterRecursiveCall(" while traversing 'typeparam' node")) { + if (_Py_EnterRecursiveCall(" while traversing 'type_param' node")) { goto failed; } res = obj2ast_int(state, tmp, &lineno, arena); @@ -12330,12 +12332,12 @@ obj2ast_typeparam(struct ast_state *state, PyObject* obj, typeparam_ty* out, return 1; } if (tmp == NULL) { - PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from typeparam"); + PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from type_param"); return 1; } else { int res; - if (_Py_EnterRecursiveCall(" while traversing 'typeparam' node")) { + if (_Py_EnterRecursiveCall(" while traversing 'type_param' node")) { goto failed; } res = obj2ast_int(state, tmp, &col_offset, arena); @@ -12352,7 +12354,7 @@ obj2ast_typeparam(struct ast_state *state, PyObject* obj, typeparam_ty* out, } else { int res; - if (_Py_EnterRecursiveCall(" while traversing 'typeparam' node")) { + if (_Py_EnterRecursiveCall(" while traversing 'type_param' node")) { goto failed; } res = obj2ast_int(state, tmp, &end_lineno, arena); @@ -12369,7 +12371,7 @@ obj2ast_typeparam(struct ast_state *state, PyObject* obj, typeparam_ty* out, } else { int res; - if (_Py_EnterRecursiveCall(" while traversing 'typeparam' node")) { + if (_Py_EnterRecursiveCall(" while traversing 'type_param' node")) { goto failed; } res = obj2ast_int(state, tmp, &end_col_offset, arena); @@ -12486,7 +12488,7 @@ obj2ast_typeparam(struct ast_state *state, PyObject* obj, typeparam_ty* out, return 0; } - PyErr_Format(PyExc_TypeError, "expected some sort of typeparam, but got %R", obj); + PyErr_Format(PyExc_TypeError, "expected some sort of type_param, but got %R", obj); failed: Py_XDECREF(tmp); return 1; @@ -12880,7 +12882,7 @@ astmodule_exec(PyObject *m) if (PyModule_AddObjectRef(m, "TypeIgnore", state->TypeIgnore_type) < 0) { return -1; } - if (PyModule_AddObjectRef(m, "typeparam", state->typeparam_type) < 0) { + if (PyModule_AddObjectRef(m, "type_param", state->type_param_type) < 0) { return -1; } if (PyModule_AddObjectRef(m, "TypeVar", state->TypeVar_type) < 0) { diff --git a/Python/ast.c b/Python/ast.c index 0844f2a..68600ce 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -17,12 +17,12 @@ struct validator { static int validate_stmts(struct validator *, asdl_stmt_seq *); static int validate_exprs(struct validator *, asdl_expr_seq *, expr_context_ty, int); static int validate_patterns(struct validator *, asdl_pattern_seq *, int); -static int validate_typeparams(struct validator *, asdl_typeparam_seq *); +static int validate_type_params(struct validator *, asdl_type_param_seq *); static int _validate_nonempty_seq(asdl_seq *, const char *, const char *); static int validate_stmt(struct validator *, stmt_ty); static int validate_expr(struct validator *, expr_ty, expr_context_ty); static int validate_pattern(struct validator *, pattern_ty, int); -static int validate_typeparam(struct validator *, typeparam_ty); +static int validate_typeparam(struct validator *, type_param_ty); #define VALIDATE_POSITIONS(node) \ if (node->lineno > node->end_lineno) { \ @@ -728,7 +728,7 @@ validate_stmt(struct validator *state, stmt_ty stmt) switch (stmt->kind) { case FunctionDef_kind: ret = validate_body(state, stmt->v.FunctionDef.body, "FunctionDef") && - validate_typeparams(state, stmt->v.FunctionDef.typeparams) && + validate_type_params(state, stmt->v.FunctionDef.type_params) && validate_arguments(state, stmt->v.FunctionDef.args) && validate_exprs(state, stmt->v.FunctionDef.decorator_list, Load, 0) && (!stmt->v.FunctionDef.returns || @@ -736,7 +736,7 @@ validate_stmt(struct validator *state, stmt_ty stmt) break; case ClassDef_kind: ret = validate_body(state, stmt->v.ClassDef.body, "ClassDef") && - validate_typeparams(state, stmt->v.ClassDef.typeparams) && + validate_type_params(state, stmt->v.ClassDef.type_params) && validate_exprs(state, stmt->v.ClassDef.bases, Load, 0) && validate_keywords(state, stmt->v.ClassDef.keywords) && validate_exprs(state, stmt->v.ClassDef.decorator_list, Load, 0); @@ -769,7 +769,7 @@ validate_stmt(struct validator *state, stmt_ty stmt) break; case TypeAlias_kind: ret = validate_expr(state, stmt->v.TypeAlias.name, Store) && - validate_typeparams(state, stmt->v.TypeAlias.typeparams) && + validate_type_params(state, stmt->v.TypeAlias.type_params) && validate_expr(state, stmt->v.TypeAlias.value, Load); break; case For_kind: @@ -919,7 +919,7 @@ validate_stmt(struct validator *state, stmt_ty stmt) break; case AsyncFunctionDef_kind: ret = validate_body(state, stmt->v.AsyncFunctionDef.body, "AsyncFunctionDef") && - validate_typeparams(state, stmt->v.AsyncFunctionDef.typeparams) && + validate_type_params(state, stmt->v.AsyncFunctionDef.type_params) && validate_arguments(state, stmt->v.AsyncFunctionDef.args) && validate_exprs(state, stmt->v.AsyncFunctionDef.decorator_list, Load, 0) && (!stmt->v.AsyncFunctionDef.returns || @@ -993,7 +993,7 @@ validate_patterns(struct validator *state, asdl_pattern_seq *patterns, int star_ } static int -validate_typeparam(struct validator *state, typeparam_ty tp) +validate_typeparam(struct validator *state, type_param_ty tp) { VALIDATE_POSITIONS(tp); int ret = -1; @@ -1014,11 +1014,11 @@ validate_typeparam(struct validator *state, typeparam_ty tp) } static int -validate_typeparams(struct validator *state, asdl_typeparam_seq *tps) +validate_type_params(struct validator *state, asdl_type_param_seq *tps) { Py_ssize_t i; for (i = 0; i < asdl_seq_LEN(tps); i++) { - typeparam_ty tp = asdl_seq_GET(tps, i); + type_param_ty tp = asdl_seq_GET(tps, i); if (tp) { if (!validate_typeparam(state, tp)) return 0; diff --git a/Python/ast_opt.c b/Python/ast_opt.c index c5b3e07..274bd13 100644 --- a/Python/ast_opt.c +++ b/Python/ast_opt.c @@ -642,7 +642,7 @@ static int astfold_withitem(withitem_ty node_, PyArena *ctx_, _PyASTOptimizeStat static int astfold_excepthandler(excepthandler_ty node_, PyArena *ctx_, _PyASTOptimizeState *state); static int astfold_match_case(match_case_ty node_, PyArena *ctx_, _PyASTOptimizeState *state); static int astfold_pattern(pattern_ty node_, PyArena *ctx_, _PyASTOptimizeState *state); -static int astfold_typeparam(typeparam_ty node_, PyArena *ctx_, _PyASTOptimizeState *state); +static int astfold_type_param(type_param_ty node_, PyArena *ctx_, _PyASTOptimizeState *state); #define CALL(FUNC, TYPE, ARG) \ if (!FUNC((ARG), ctx_, state)) \ @@ -881,7 +881,7 @@ astfold_stmt(stmt_ty node_, PyArena *ctx_, _PyASTOptimizeState *state) } switch (node_->kind) { case FunctionDef_kind: - CALL_SEQ(astfold_typeparam, typeparam, node_->v.FunctionDef.typeparams); + CALL_SEQ(astfold_type_param, type_param, node_->v.FunctionDef.type_params); CALL(astfold_arguments, arguments_ty, node_->v.FunctionDef.args); CALL(astfold_body, asdl_seq, node_->v.FunctionDef.body); CALL_SEQ(astfold_expr, expr, node_->v.FunctionDef.decorator_list); @@ -890,7 +890,7 @@ astfold_stmt(stmt_ty node_, PyArena *ctx_, _PyASTOptimizeState *state) } break; case AsyncFunctionDef_kind: - CALL_SEQ(astfold_typeparam, typeparam, node_->v.AsyncFunctionDef.typeparams); + CALL_SEQ(astfold_type_param, type_param, node_->v.AsyncFunctionDef.type_params); CALL(astfold_arguments, arguments_ty, node_->v.AsyncFunctionDef.args); CALL(astfold_body, asdl_seq, node_->v.AsyncFunctionDef.body); CALL_SEQ(astfold_expr, expr, node_->v.AsyncFunctionDef.decorator_list); @@ -899,7 +899,7 @@ astfold_stmt(stmt_ty node_, PyArena *ctx_, _PyASTOptimizeState *state) } break; case ClassDef_kind: - CALL_SEQ(astfold_typeparam, typeparam, node_->v.ClassDef.typeparams); + CALL_SEQ(astfold_type_param, type_param, node_->v.ClassDef.type_params); CALL_SEQ(astfold_expr, expr, node_->v.ClassDef.bases); CALL_SEQ(astfold_keyword, keyword, node_->v.ClassDef.keywords); CALL(astfold_body, asdl_seq, node_->v.ClassDef.body); @@ -928,7 +928,7 @@ astfold_stmt(stmt_ty node_, PyArena *ctx_, _PyASTOptimizeState *state) break; case TypeAlias_kind: CALL(astfold_expr, expr_ty, node_->v.TypeAlias.name); - CALL_SEQ(astfold_typeparam, typeparam, node_->v.TypeAlias.typeparams); + CALL_SEQ(astfold_type_param, type_param, node_->v.TypeAlias.type_params); CALL(astfold_expr, expr_ty, node_->v.TypeAlias.value); break; case For_kind: @@ -1084,7 +1084,7 @@ astfold_match_case(match_case_ty node_, PyArena *ctx_, _PyASTOptimizeState *stat } static int -astfold_typeparam(typeparam_ty node_, PyArena *ctx_, _PyASTOptimizeState *state) +astfold_type_param(type_param_ty node_, PyArena *ctx_, _PyASTOptimizeState *state) { switch (node_->kind) { case TypeVar_kind: diff --git a/Python/compile.c b/Python/compile.c index e4dc972..f2314ae 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -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); diff --git a/Python/symtable.c b/Python/symtable.c index 73cbb2b..e2c00d1 100644 --- a/Python/symtable.c +++ b/Python/symtable.c @@ -231,7 +231,7 @@ static int symtable_enter_block(struct symtable *st, identifier name, static int symtable_exit_block(struct symtable *st); static int symtable_visit_stmt(struct symtable *st, stmt_ty s); static int symtable_visit_expr(struct symtable *st, expr_ty s); -static int symtable_visit_typeparam(struct symtable *st, typeparam_ty s); +static int symtable_visit_type_param(struct symtable *st, type_param_ty s); static int symtable_visit_genexp(struct symtable *st, expr_ty s); static int symtable_visit_listcomp(struct symtable *st, expr_ty s); static int symtable_visit_setcomp(struct symtable *st, expr_ty s); @@ -528,7 +528,7 @@ error_at_directive(PySTEntryObject *ste, PyObject *name) static int analyze_name(PySTEntryObject *ste, PyObject *scopes, PyObject *name, long flags, PyObject *bound, PyObject *local, PyObject *free, - PyObject *global, PyObject *typeparams, PySTEntryObject *class_entry) + PyObject *global, PyObject *type_params, PySTEntryObject *class_entry) { if (flags & DEF_GLOBAL) { if (flags & DEF_NONLOCAL) { @@ -557,7 +557,7 @@ analyze_name(PySTEntryObject *ste, PyObject *scopes, PyObject *name, long flags, return error_at_directive(ste, name); } - if (PySet_Contains(typeparams, name)) { + if (PySet_Contains(type_params, name)) { PyErr_Format(PyExc_SyntaxError, "nonlocal binding not allowed for type parameter '%U'", name); @@ -574,11 +574,11 @@ analyze_name(PySTEntryObject *ste, PyObject *scopes, PyObject *name, long flags, if (PySet_Discard(global, name) < 0) return 0; if (flags & DEF_TYPE_PARAM) { - if (PySet_Add(typeparams, name) < 0) + if (PySet_Add(type_params, name) < 0) return 0; } else { - if (PySet_Discard(typeparams, name) < 0) + if (PySet_Discard(type_params, name) < 0) return 0; } return 1; @@ -871,12 +871,12 @@ error: static int analyze_child_block(PySTEntryObject *entry, PyObject *bound, PyObject *free, - PyObject *global, PyObject *typeparams, + PyObject *global, PyObject *type_params, PySTEntryObject *class_entry, PyObject **child_free); static int analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free, - PyObject *global, PyObject *typeparams, + PyObject *global, PyObject *type_params, PySTEntryObject *class_entry) { PyObject *name, *v, *local = NULL, *scopes = NULL, *newbound = NULL; @@ -939,7 +939,7 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free, while (PyDict_Next(ste->ste_symbols, &pos, &name, &v)) { long flags = PyLong_AS_LONG(v); if (!analyze_name(ste, scopes, name, flags, - bound, local, free, global, typeparams, class_entry)) + bound, local, free, global, type_params, class_entry)) goto error; } @@ -1002,7 +1002,7 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free, !entry->ste_generator; if (!analyze_child_block(entry, newbound, newfree, newglobal, - typeparams, new_class_entry, &child_free)) + type_params, new_class_entry, &child_free)) { goto error; } @@ -1066,11 +1066,11 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free, static int analyze_child_block(PySTEntryObject *entry, PyObject *bound, PyObject *free, - PyObject *global, PyObject *typeparams, + PyObject *global, PyObject *type_params, PySTEntryObject *class_entry, PyObject** child_free) { PyObject *temp_bound = NULL, *temp_global = NULL, *temp_free = NULL; - PyObject *temp_typeparams = NULL; + PyObject *temp_type_params = NULL; /* Copy the bound/global/free sets. @@ -1088,30 +1088,30 @@ analyze_child_block(PySTEntryObject *entry, PyObject *bound, PyObject *free, temp_global = PySet_New(global); if (!temp_global) goto error; - temp_typeparams = PySet_New(typeparams); - if (!temp_typeparams) + temp_type_params = PySet_New(type_params); + if (!temp_type_params) goto error; if (!analyze_block(entry, temp_bound, temp_free, temp_global, - temp_typeparams, class_entry)) + temp_type_params, class_entry)) goto error; *child_free = temp_free; Py_DECREF(temp_bound); Py_DECREF(temp_global); - Py_DECREF(temp_typeparams); + Py_DECREF(temp_type_params); return 1; error: Py_XDECREF(temp_bound); Py_XDECREF(temp_free); Py_XDECREF(temp_global); - Py_XDECREF(temp_typeparams); + Py_XDECREF(temp_type_params); return 0; } static int symtable_analyze(struct symtable *st) { - PyObject *free, *global, *typeparams; + PyObject *free, *global, *type_params; int r; free = PySet_New(NULL); @@ -1122,16 +1122,16 @@ symtable_analyze(struct symtable *st) Py_DECREF(free); return 0; } - typeparams = PySet_New(NULL); - if (!typeparams) { + type_params = PySet_New(NULL); + if (!type_params) { Py_DECREF(free); Py_DECREF(global); return 0; } - r = analyze_block(st->st_top, NULL, free, global, typeparams, NULL); + r = analyze_block(st->st_top, NULL, free, global, type_params, NULL); Py_DECREF(free); Py_DECREF(global); - Py_DECREF(typeparams); + Py_DECREF(type_params); return r; } @@ -1313,7 +1313,7 @@ symtable_add_def(struct symtable *st, PyObject *name, int flag, } static int -symtable_enter_typeparam_block(struct symtable *st, identifier name, +symtable_enter_type_param_block(struct symtable *st, identifier name, void *ast, int has_defaults, int has_kwdefaults, enum _stmt_kind kind, int lineno, int col_offset, @@ -1472,10 +1472,10 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s) VISIT_SEQ_WITH_NULL(st, expr, s->v.FunctionDef.args->kw_defaults); if (s->v.FunctionDef.decorator_list) VISIT_SEQ(st, expr, s->v.FunctionDef.decorator_list); - if (asdl_seq_LEN(s->v.FunctionDef.typeparams) > 0) { - if (!symtable_enter_typeparam_block( + if (asdl_seq_LEN(s->v.FunctionDef.type_params) > 0) { + if (!symtable_enter_type_param_block( st, s->v.FunctionDef.name, - (void *)s->v.FunctionDef.typeparams, + (void *)s->v.FunctionDef.type_params, s->v.FunctionDef.args->defaults != NULL, has_kwonlydefaults(s->v.FunctionDef.args->kwonlyargs, s->v.FunctionDef.args->kw_defaults), @@ -1483,7 +1483,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s) LOCATION(s))) { VISIT_QUIT(st, 0); } - VISIT_SEQ(st, typeparam, s->v.FunctionDef.typeparams); + VISIT_SEQ(st, type_param, s->v.FunctionDef.type_params); } if (!symtable_visit_annotations(st, s, s->v.FunctionDef.args, s->v.FunctionDef.returns)) @@ -1496,7 +1496,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s) VISIT_SEQ(st, stmt, s->v.FunctionDef.body); if (!symtable_exit_block(st)) VISIT_QUIT(st, 0); - if (asdl_seq_LEN(s->v.FunctionDef.typeparams) > 0) { + if (asdl_seq_LEN(s->v.FunctionDef.type_params) > 0) { if (!symtable_exit_block(st)) VISIT_QUIT(st, 0); } @@ -1507,14 +1507,14 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s) VISIT_QUIT(st, 0); if (s->v.ClassDef.decorator_list) VISIT_SEQ(st, expr, s->v.ClassDef.decorator_list); - if (asdl_seq_LEN(s->v.ClassDef.typeparams) > 0) { - if (!symtable_enter_typeparam_block(st, s->v.ClassDef.name, - (void *)s->v.ClassDef.typeparams, + if (asdl_seq_LEN(s->v.ClassDef.type_params) > 0) { + if (!symtable_enter_type_param_block(st, s->v.ClassDef.name, + (void *)s->v.ClassDef.type_params, false, false, s->kind, LOCATION(s))) { VISIT_QUIT(st, 0); } - VISIT_SEQ(st, typeparam, s->v.ClassDef.typeparams); + VISIT_SEQ(st, type_param, s->v.ClassDef.type_params); } VISIT_SEQ(st, expr, s->v.ClassDef.bases); VISIT_SEQ(st, keyword, s->v.ClassDef.keywords); @@ -1524,7 +1524,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s) VISIT_QUIT(st, 0); tmp = st->st_private; st->st_private = s->v.ClassDef.name; - if (asdl_seq_LEN(s->v.ClassDef.typeparams) > 0) { + if (asdl_seq_LEN(s->v.ClassDef.type_params) > 0) { if (!symtable_add_def(st, &_Py_ID(__type_params__), DEF_LOCAL, LOCATION(s))) { VISIT_QUIT(st, 0); @@ -1539,7 +1539,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s) st->st_private = tmp; if (!symtable_exit_block(st)) VISIT_QUIT(st, 0); - if (asdl_seq_LEN(s->v.ClassDef.typeparams) > 0) { + if (asdl_seq_LEN(s->v.ClassDef.type_params) > 0) { if (!symtable_exit_block(st)) VISIT_QUIT(st, 0); } @@ -1550,16 +1550,16 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s) assert(s->v.TypeAlias.name->kind == Name_kind); PyObject *name = s->v.TypeAlias.name->v.Name.id; int is_in_class = st->st_cur->ste_type == ClassBlock; - int is_generic = asdl_seq_LEN(s->v.TypeAlias.typeparams) > 0; + int is_generic = asdl_seq_LEN(s->v.TypeAlias.type_params) > 0; if (is_generic) { - if (!symtable_enter_typeparam_block( + if (!symtable_enter_type_param_block( st, name, - (void *)s->v.TypeAlias.typeparams, + (void *)s->v.TypeAlias.type_params, false, false, s->kind, LOCATION(s))) { VISIT_QUIT(st, 0); } - VISIT_SEQ(st, typeparam, s->v.TypeAlias.typeparams); + VISIT_SEQ(st, type_param, s->v.TypeAlias.type_params); } if (!symtable_enter_block(st, name, TypeAliasBlock, (void *)s, LOCATION(s))) @@ -1785,10 +1785,10 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s) s->v.AsyncFunctionDef.args->kw_defaults); if (s->v.AsyncFunctionDef.decorator_list) VISIT_SEQ(st, expr, s->v.AsyncFunctionDef.decorator_list); - if (asdl_seq_LEN(s->v.AsyncFunctionDef.typeparams) > 0) { - if (!symtable_enter_typeparam_block( + if (asdl_seq_LEN(s->v.AsyncFunctionDef.type_params) > 0) { + if (!symtable_enter_type_param_block( st, s->v.AsyncFunctionDef.name, - (void *)s->v.AsyncFunctionDef.typeparams, + (void *)s->v.AsyncFunctionDef.type_params, s->v.AsyncFunctionDef.args->defaults != NULL, has_kwonlydefaults(s->v.AsyncFunctionDef.args->kwonlyargs, s->v.AsyncFunctionDef.args->kw_defaults), @@ -1796,7 +1796,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s) LOCATION(s))) { VISIT_QUIT(st, 0); } - VISIT_SEQ(st, typeparam, s->v.AsyncFunctionDef.typeparams); + VISIT_SEQ(st, type_param, s->v.AsyncFunctionDef.type_params); } if (!symtable_visit_annotations(st, s, s->v.AsyncFunctionDef.args, s->v.AsyncFunctionDef.returns)) @@ -1811,7 +1811,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s) VISIT_SEQ(st, stmt, s->v.AsyncFunctionDef.body); if (!symtable_exit_block(st)) VISIT_QUIT(st, 0); - if (asdl_seq_LEN(s->v.AsyncFunctionDef.typeparams) > 0) { + if (asdl_seq_LEN(s->v.AsyncFunctionDef.type_params) > 0) { if (!symtable_exit_block(st)) VISIT_QUIT(st, 0); } @@ -2110,7 +2110,7 @@ symtable_visit_expr(struct symtable *st, expr_ty e) } static int -symtable_visit_typeparam(struct symtable *st, typeparam_ty tp) +symtable_visit_type_param(struct symtable *st, type_param_ty tp) { if (++st->recursion_depth > st->recursion_limit) { PyErr_SetString(PyExc_RecursionError, |