[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 ba73473f4c)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
Miss Islington (bot) 2023-05-30 07:33:01 -07:00 committed by GitHub
parent fd6b913535
commit 7899fac3c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 365 additions and 334 deletions

View file

@ -8,19 +8,19 @@ module Python
| Expression(expr body)
| FunctionType(expr* argtypes, expr returns)
stmt = FunctionDef(identifier name, type_param* type_params, arguments args,
stmt = FunctionDef(identifier name, arguments args,
stmt* body, expr* decorator_list, expr? returns,
string? type_comment)
| AsyncFunctionDef(identifier name, type_param* type_params, arguments args,
string? type_comment, type_param* type_params)
| AsyncFunctionDef(identifier name, arguments args,
stmt* body, expr* decorator_list, expr? returns,
string? type_comment)
string? type_comment, type_param* type_params)
| ClassDef(identifier name,
type_param* type_params,
expr* bases,
keyword* keywords,
stmt* body,
expr* decorator_list)
expr* decorator_list,
type_param* type_params)
| Return(expr? value)
| Delete(expr* targets)

View file

@ -752,22 +752,25 @@ _PyPegen_function_def_decorators(Parser *p, asdl_expr_seq *decorators, stmt_ty f
assert(function_def != NULL);
if (function_def->kind == AsyncFunctionDef_kind) {
return _PyAST_AsyncFunctionDef(
function_def->v.FunctionDef.name, function_def->v.FunctionDef.type_params,
function_def->v.FunctionDef.args,
function_def->v.FunctionDef.body, decorators, function_def->v.FunctionDef.returns,
function_def->v.FunctionDef.type_comment, function_def->lineno,
function_def->col_offset, function_def->end_lineno, function_def->end_col_offset,
p->arena);
function_def->v.AsyncFunctionDef.name,
function_def->v.AsyncFunctionDef.args,
function_def->v.AsyncFunctionDef.body, decorators,
function_def->v.AsyncFunctionDef.returns,
function_def->v.AsyncFunctionDef.type_comment,
function_def->v.AsyncFunctionDef.type_params,
function_def->lineno, function_def->col_offset,
function_def->end_lineno, function_def->end_col_offset, p->arena);
}
return _PyAST_FunctionDef(
function_def->v.FunctionDef.name, function_def->v.FunctionDef.type_params,
function_def->v.FunctionDef.name,
function_def->v.FunctionDef.args,
function_def->v.FunctionDef.body, decorators,
function_def->v.FunctionDef.returns,
function_def->v.FunctionDef.type_comment, function_def->lineno,
function_def->col_offset, function_def->end_lineno,
function_def->end_col_offset, p->arena);
function_def->v.FunctionDef.type_comment,
function_def->v.FunctionDef.type_params,
function_def->lineno, function_def->col_offset,
function_def->end_lineno, function_def->end_col_offset, p->arena);
}
/* Construct a ClassDef equivalent to class_def, but with decorators */
@ -776,9 +779,10 @@ _PyPegen_class_def_decorators(Parser *p, asdl_expr_seq *decorators, stmt_ty clas
{
assert(class_def != NULL);
return _PyAST_ClassDef(
class_def->v.ClassDef.name, class_def->v.ClassDef.type_params,
class_def->v.ClassDef.name,
class_def->v.ClassDef.bases, class_def->v.ClassDef.keywords,
class_def->v.ClassDef.body, decorators,
class_def->v.ClassDef.type_params,
class_def->lineno, class_def->col_offset, class_def->end_lineno,
class_def->end_col_offset, p->arena);
}

6
Parser/parser.c generated
View file

@ -4425,7 +4425,7 @@ class_def_raw_rule(Parser *p)
UNUSED(_end_lineno); // Only used by EXTRA macro
int _end_col_offset = _token->end_col_offset;
UNUSED(_end_col_offset); // Only used by EXTRA macro
_res = _PyAST_ClassDef ( a -> v . Name . id , t , ( b ) ? ( ( expr_ty ) b ) -> v . Call . args : NULL , ( b ) ? ( ( expr_ty ) b ) -> v . Call . keywords : NULL , c , NULL , EXTRA );
_res = _PyAST_ClassDef ( a -> v . Name . id , ( b ) ? ( ( expr_ty ) b ) -> v . Call . args : NULL , ( b ) ? ( ( expr_ty ) b ) -> v . Call . keywords : NULL , c , NULL , t , EXTRA );
if (_res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
p->level--;
@ -4602,7 +4602,7 @@ function_def_raw_rule(Parser *p)
UNUSED(_end_lineno); // Only used by EXTRA macro
int _end_col_offset = _token->end_col_offset;
UNUSED(_end_col_offset); // Only used by EXTRA macro
_res = _PyAST_FunctionDef ( n -> v . Name . id , t , ( params ) ? params : CHECK ( arguments_ty , _PyPegen_empty_arguments ( p ) ) , b , NULL , a , NEW_TYPE_COMMENT ( p , tc ) , EXTRA );
_res = _PyAST_FunctionDef ( n -> v . Name . id , ( params ) ? params : CHECK ( arguments_ty , _PyPegen_empty_arguments ( p ) ) , b , NULL , a , NEW_TYPE_COMMENT ( p , tc ) , t , EXTRA );
if (_res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
p->level--;
@ -4665,7 +4665,7 @@ function_def_raw_rule(Parser *p)
UNUSED(_end_lineno); // Only used by EXTRA macro
int _end_col_offset = _token->end_col_offset;
UNUSED(_end_col_offset); // Only used by EXTRA macro
_res = CHECK_VERSION ( stmt_ty , 5 , "Async functions are" , _PyAST_AsyncFunctionDef ( n -> v . Name . id , t , ( params ) ? params : CHECK ( arguments_ty , _PyPegen_empty_arguments ( p ) ) , b , NULL , a , NEW_TYPE_COMMENT ( p , tc ) , EXTRA ) );
_res = CHECK_VERSION ( stmt_ty , 5 , "Async functions are" , _PyAST_AsyncFunctionDef ( n -> v . Name . id , ( params ) ? params : CHECK ( arguments_ty , _PyPegen_empty_arguments ( p ) ) , b , NULL , a , NEW_TYPE_COMMENT ( p , tc ) , t , EXTRA ) );
if (_res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
p->level--;