summaryrefslogtreecommitdiffstats
path: root/Python/Python-ast.c
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-05-30 14:33:01 (GMT)
committerGitHub <noreply@github.com>2023-05-30 14:33:01 (GMT)
commit7899fac3c5fba3b8258cdd72562230c51164d778 (patch)
treed9e771cc2c0b2e8dc7bba37e754c3e59e9410ea3 /Python/Python-ast.c
parentfd6b913535d78d3bfec710075ac930474c1057ca (diff)
downloadcpython-7899fac3c5fba3b8258cdd72562230c51164d778.zip
cpython-7899fac3c5fba3b8258cdd72562230c51164d778.tar.gz
cpython-7899fac3c5fba3b8258cdd72562230c51164d778.tar.bz2
[3.12] gh-104799: Move location of type_params AST fields (GH-104828) (#104974)
gh-104799: Move location of type_params AST fields (GH-104828) (cherry picked from commit ba73473f4c18ba4cf7ab18d84d94a47d2d37a0c5) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Diffstat (limited to 'Python/Python-ast.c')
-rw-r--r--Python/Python-ast.c325
1 files changed, 162 insertions, 163 deletions
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
index 87906d9..030c082 100644
--- a/Python/Python-ast.c
+++ b/Python/Python-ast.c
@@ -409,29 +409,29 @@ static const char * const stmt_attributes[] = {
static PyObject* ast2obj_stmt(struct ast_state *state, void*);
static const char * const FunctionDef_fields[]={
"name",
- "type_params",
"args",
"body",
"decorator_list",
"returns",
"type_comment",
+ "type_params",
};
static const char * const AsyncFunctionDef_fields[]={
"name",
- "type_params",
"args",
"body",
"decorator_list",
"returns",
"type_comment",
+ "type_params",
};
static const char * const ClassDef_fields[]={
"name",
- "type_params",
"bases",
"keywords",
"body",
"decorator_list",
+ "type_params",
};
static const char * const Return_fields[]={
"value",
@@ -1169,9 +1169,9 @@ 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, 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"
+ "stmt = FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment, type_param* type_params)\n"
+ " | AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment, type_param* type_params)\n"
+ " | ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list, type_param* type_params)\n"
" | Return(expr? value)\n"
" | Delete(expr* targets)\n"
" | Assign(expr* targets, expr value, 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, type_param* type_params, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)");
+ "FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment, type_param* type_params)");
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, type_param* type_params, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)");
+ "AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment, type_param* type_params)");
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, type_param* type_params, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)");
+ "ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list, type_param* type_params)");
if (!state->ClassDef_type) return 0;
state->Return_type = make_type(state, "Return", state->stmt_type,
Return_fields, 1,
@@ -2032,11 +2032,11 @@ _PyAST_FunctionType(asdl_expr_seq * argtypes, expr_ty returns, PyArena *arena)
}
stmt_ty
-_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,
- PyArena *arena)
+_PyAST_FunctionDef(identifier name, arguments_ty args, asdl_stmt_seq * body,
+ asdl_expr_seq * decorator_list, expr_ty returns, string
+ type_comment, asdl_type_param_seq * type_params, int lineno,
+ int col_offset, int end_lineno, int end_col_offset, PyArena
+ *arena)
{
stmt_ty p;
if (!name) {
@@ -2054,12 +2054,12 @@ _PyAST_FunctionDef(identifier name, asdl_type_param_seq * type_params,
return NULL;
p->kind = FunctionDef_kind;
p->v.FunctionDef.name = name;
- p->v.FunctionDef.type_params = type_params;
p->v.FunctionDef.args = args;
p->v.FunctionDef.body = body;
p->v.FunctionDef.decorator_list = decorator_list;
p->v.FunctionDef.returns = returns;
p->v.FunctionDef.type_comment = type_comment;
+ p->v.FunctionDef.type_params = type_params;
p->lineno = lineno;
p->col_offset = col_offset;
p->end_lineno = end_lineno;
@@ -2068,9 +2068,9 @@ _PyAST_FunctionDef(identifier name, asdl_type_param_seq * type_params,
}
stmt_ty
-_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,
+_PyAST_AsyncFunctionDef(identifier name, arguments_ty args, asdl_stmt_seq *
+ body, asdl_expr_seq * decorator_list, expr_ty returns,
+ string type_comment, asdl_type_param_seq * type_params,
int lineno, int col_offset, int end_lineno, int
end_col_offset, PyArena *arena)
{
@@ -2090,12 +2090,12 @@ _PyAST_AsyncFunctionDef(identifier name, asdl_type_param_seq * type_params,
return NULL;
p->kind = AsyncFunctionDef_kind;
p->v.AsyncFunctionDef.name = name;
- p->v.AsyncFunctionDef.type_params = type_params;
p->v.AsyncFunctionDef.args = args;
p->v.AsyncFunctionDef.body = body;
p->v.AsyncFunctionDef.decorator_list = decorator_list;
p->v.AsyncFunctionDef.returns = returns;
p->v.AsyncFunctionDef.type_comment = type_comment;
+ p->v.AsyncFunctionDef.type_params = type_params;
p->lineno = lineno;
p->col_offset = col_offset;
p->end_lineno = end_lineno;
@@ -2104,11 +2104,10 @@ _PyAST_AsyncFunctionDef(identifier name, asdl_type_param_seq * type_params,
}
stmt_ty
-_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)
+_PyAST_ClassDef(identifier name, asdl_expr_seq * bases, asdl_keyword_seq *
+ keywords, asdl_stmt_seq * body, asdl_expr_seq * decorator_list,
+ asdl_type_param_seq * type_params, int lineno, int col_offset,
+ int end_lineno, int end_col_offset, PyArena *arena)
{
stmt_ty p;
if (!name) {
@@ -2121,11 +2120,11 @@ _PyAST_ClassDef(identifier name, asdl_type_param_seq * type_params,
return NULL;
p->kind = ClassDef_kind;
p->v.ClassDef.name = name;
- p->v.ClassDef.type_params = type_params;
p->v.ClassDef.bases = bases;
p->v.ClassDef.keywords = keywords;
p->v.ClassDef.body = body;
p->v.ClassDef.decorator_list = decorator_list;
+ p->v.ClassDef.type_params = type_params;
p->lineno = lineno;
p->col_offset = col_offset;
p->end_lineno = end_lineno;
@@ -3883,12 +3882,6 @@ 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.type_params,
- ast2obj_type_param);
- if (!value) goto failed;
- if (PyObject_SetAttr(result, state->type_params, value) == -1)
- goto failed;
- Py_DECREF(value);
value = ast2obj_arguments(state, o->v.FunctionDef.args);
if (!value) goto failed;
if (PyObject_SetAttr(result, state->args, value) == -1)
@@ -3916,6 +3909,12 @@ ast2obj_stmt(struct ast_state *state, void* _o)
if (PyObject_SetAttr(result, state->type_comment, value) == -1)
goto failed;
Py_DECREF(value);
+ value = ast2obj_list(state, (asdl_seq*)o->v.FunctionDef.type_params,
+ ast2obj_type_param);
+ if (!value) goto failed;
+ if (PyObject_SetAttr(result, state->type_params, value) == -1)
+ goto failed;
+ Py_DECREF(value);
break;
case AsyncFunctionDef_kind:
tp = (PyTypeObject *)state->AsyncFunctionDef_type;
@@ -3926,13 +3925,6 @@ 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.AsyncFunctionDef.type_params,
- ast2obj_type_param);
- if (!value) goto failed;
- if (PyObject_SetAttr(result, state->type_params, value) == -1)
- goto failed;
- Py_DECREF(value);
value = ast2obj_arguments(state, o->v.AsyncFunctionDef.args);
if (!value) goto failed;
if (PyObject_SetAttr(result, state->args, value) == -1)
@@ -3961,6 +3953,13 @@ ast2obj_stmt(struct ast_state *state, void* _o)
if (PyObject_SetAttr(result, state->type_comment, value) == -1)
goto failed;
Py_DECREF(value);
+ value = ast2obj_list(state,
+ (asdl_seq*)o->v.AsyncFunctionDef.type_params,
+ ast2obj_type_param);
+ if (!value) goto failed;
+ if (PyObject_SetAttr(result, state->type_params, value) == -1)
+ goto failed;
+ Py_DECREF(value);
break;
case ClassDef_kind:
tp = (PyTypeObject *)state->ClassDef_type;
@@ -3971,12 +3970,6 @@ 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.type_params,
- ast2obj_type_param);
- if (!value) goto failed;
- if (PyObject_SetAttr(result, state->type_params, value) == -1)
- goto failed;
- Py_DECREF(value);
value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.bases,
ast2obj_expr);
if (!value) goto failed;
@@ -4001,6 +3994,12 @@ ast2obj_stmt(struct ast_state *state, void* _o)
if (PyObject_SetAttr(result, state->decorator_list, value) == -1)
goto failed;
Py_DECREF(value);
+ value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.type_params,
+ ast2obj_type_param);
+ if (!value) goto failed;
+ if (PyObject_SetAttr(result, state->type_params, value) == -1)
+ goto failed;
+ Py_DECREF(value);
break;
case Return_kind:
tp = (PyTypeObject *)state->Return_type;
@@ -6075,12 +6074,12 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena*
}
if (isinstance) {
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;
+ asdl_type_param_seq* type_params;
if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
return 1;
@@ -6099,42 +6098,6 @@ 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->type_params, &tmp) < 0) {
- return 1;
- }
- if (tmp == NULL) {
- PyErr_SetString(PyExc_TypeError, "required field \"type_params\" missing from FunctionDef");
- return 1;
- }
- else {
- int res;
- Py_ssize_t len;
- Py_ssize_t i;
- if (!PyList_Check(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);
- type_params = _Py_asdl_type_param_seq_new(len, arena);
- if (type_params == NULL) goto failed;
- for (i = 0; i < len; i++) {
- type_param_ty val;
- PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
- if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
- goto failed;
- }
- 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 \"type_params\" changed size during iteration");
- goto failed;
- }
- asdl_seq_SET(type_params, i, val);
- }
- Py_CLEAR(tmp);
- }
if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
return 1;
}
@@ -6258,10 +6221,46 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena*
if (res != 0) goto failed;
Py_CLEAR(tmp);
}
- *out = _PyAST_FunctionDef(name, type_params, args, body,
- decorator_list, returns, type_comment,
- lineno, col_offset, end_lineno,
- end_col_offset, arena);
+ if (_PyObject_LookupAttr(obj, state->type_params, &tmp) < 0) {
+ return 1;
+ }
+ if (tmp == NULL) {
+ PyErr_SetString(PyExc_TypeError, "required field \"type_params\" missing from FunctionDef");
+ return 1;
+ }
+ else {
+ int res;
+ Py_ssize_t len;
+ Py_ssize_t i;
+ if (!PyList_Check(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);
+ type_params = _Py_asdl_type_param_seq_new(len, arena);
+ if (type_params == NULL) goto failed;
+ for (i = 0; i < len; i++) {
+ type_param_ty val;
+ PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
+ if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
+ goto failed;
+ }
+ 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 \"type_params\" changed size during iteration");
+ goto failed;
+ }
+ asdl_seq_SET(type_params, i, val);
+ }
+ Py_CLEAR(tmp);
+ }
+ *out = _PyAST_FunctionDef(name, args, body, decorator_list, returns,
+ type_comment, type_params, lineno,
+ col_offset, end_lineno, end_col_offset,
+ arena);
if (*out == NULL) goto failed;
return 0;
}
@@ -6272,12 +6271,12 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena*
}
if (isinstance) {
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;
+ asdl_type_param_seq* type_params;
if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
return 1;
@@ -6296,42 +6295,6 @@ 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->type_params, &tmp) < 0) {
- return 1;
- }
- if (tmp == NULL) {
- PyErr_SetString(PyExc_TypeError, "required field \"type_params\" missing from AsyncFunctionDef");
- return 1;
- }
- else {
- int res;
- Py_ssize_t len;
- Py_ssize_t i;
- if (!PyList_Check(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);
- type_params = _Py_asdl_type_param_seq_new(len, arena);
- if (type_params == NULL) goto failed;
- for (i = 0; i < len; i++) {
- type_param_ty val;
- PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
- if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
- goto failed;
- }
- 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 \"type_params\" changed size during iteration");
- goto failed;
- }
- asdl_seq_SET(type_params, i, val);
- }
- Py_CLEAR(tmp);
- }
if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
return 1;
}
@@ -6455,8 +6418,44 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena*
if (res != 0) goto failed;
Py_CLEAR(tmp);
}
- *out = _PyAST_AsyncFunctionDef(name, type_params, args, body,
- decorator_list, returns, type_comment,
+ if (_PyObject_LookupAttr(obj, state->type_params, &tmp) < 0) {
+ return 1;
+ }
+ if (tmp == NULL) {
+ PyErr_SetString(PyExc_TypeError, "required field \"type_params\" missing from AsyncFunctionDef");
+ return 1;
+ }
+ else {
+ int res;
+ Py_ssize_t len;
+ Py_ssize_t i;
+ if (!PyList_Check(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);
+ type_params = _Py_asdl_type_param_seq_new(len, arena);
+ if (type_params == NULL) goto failed;
+ for (i = 0; i < len; i++) {
+ type_param_ty val;
+ PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
+ if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
+ goto failed;
+ }
+ 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 \"type_params\" changed size during iteration");
+ goto failed;
+ }
+ asdl_seq_SET(type_params, i, val);
+ }
+ Py_CLEAR(tmp);
+ }
+ *out = _PyAST_AsyncFunctionDef(name, args, body, decorator_list,
+ returns, type_comment, type_params,
lineno, col_offset, end_lineno,
end_col_offset, arena);
if (*out == NULL) goto failed;
@@ -6469,11 +6468,11 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena*
}
if (isinstance) {
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;
+ asdl_type_param_seq* type_params;
if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
return 1;
@@ -6492,42 +6491,6 @@ 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->type_params, &tmp) < 0) {
- return 1;
- }
- if (tmp == NULL) {
- PyErr_SetString(PyExc_TypeError, "required field \"type_params\" missing from ClassDef");
- return 1;
- }
- else {
- int res;
- Py_ssize_t len;
- Py_ssize_t i;
- if (!PyList_Check(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);
- type_params = _Py_asdl_type_param_seq_new(len, arena);
- if (type_params == NULL) goto failed;
- for (i = 0; i < len; i++) {
- type_param_ty val;
- PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
- if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
- goto failed;
- }
- 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 \"type_params\" changed size during iteration");
- goto failed;
- }
- asdl_seq_SET(type_params, i, val);
- }
- Py_CLEAR(tmp);
- }
if (_PyObject_LookupAttr(obj, state->bases, &tmp) < 0) {
return 1;
}
@@ -6672,8 +6635,44 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena*
}
Py_CLEAR(tmp);
}
- *out = _PyAST_ClassDef(name, type_params, bases, keywords, body,
- decorator_list, lineno, col_offset, end_lineno,
+ if (_PyObject_LookupAttr(obj, state->type_params, &tmp) < 0) {
+ return 1;
+ }
+ if (tmp == NULL) {
+ PyErr_SetString(PyExc_TypeError, "required field \"type_params\" missing from ClassDef");
+ return 1;
+ }
+ else {
+ int res;
+ Py_ssize_t len;
+ Py_ssize_t i;
+ if (!PyList_Check(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);
+ type_params = _Py_asdl_type_param_seq_new(len, arena);
+ if (type_params == NULL) goto failed;
+ for (i = 0; i < len; i++) {
+ type_param_ty val;
+ PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
+ if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
+ goto failed;
+ }
+ 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 \"type_params\" changed size during iteration");
+ goto failed;
+ }
+ asdl_seq_SET(type_params, i, val);
+ }
+ Py_CLEAR(tmp);
+ }
+ *out = _PyAST_ClassDef(name, bases, keywords, body, decorator_list,
+ type_params, lineno, col_offset, end_lineno,
end_col_offset, arena);
if (*out == NULL) goto failed;
return 0;