gh-104799: Move location of type_params AST fields (#104828)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
Jelle Zijlstra 2023-05-26 05:54:37 -07:00 committed by GitHub
parent 6e1eccdcce
commit ba73473f4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 297 additions and 266 deletions

View File

@ -1724,7 +1724,6 @@ Function and class definitions
body=[ body=[
FunctionDef( FunctionDef(
name='f', name='f',
type_params=[],
args=arguments( args=arguments(
posonlyargs=[], posonlyargs=[],
args=[ args=[
@ -1749,7 +1748,8 @@ Function and class definitions
decorator_list=[ decorator_list=[
Name(id='decorator1', ctx=Load()), Name(id='decorator1', ctx=Load()),
Name(id='decorator2', ctx=Load())], Name(id='decorator2', ctx=Load())],
returns=Constant(value='return annotation'))], returns=Constant(value='return annotation'),
type_params=[])],
type_ignores=[]) type_ignores=[])
@ -1848,7 +1848,6 @@ Function and class definitions
body=[ body=[
ClassDef( ClassDef(
name='Foo', name='Foo',
type_params=[],
bases=[ bases=[
Name(id='base1', ctx=Load()), Name(id='base1', ctx=Load()),
Name(id='base2', ctx=Load())], Name(id='base2', ctx=Load())],
@ -1860,7 +1859,8 @@ Function and class definitions
Pass()], Pass()],
decorator_list=[ decorator_list=[
Name(id='decorator1', ctx=Load()), Name(id='decorator1', ctx=Load()),
Name(id='decorator2', ctx=Load())])], Name(id='decorator2', ctx=Load())],
type_params=[])],
type_ignores=[]) type_ignores=[])
Async and await Async and await
@ -1887,7 +1887,6 @@ Async and await
body=[ body=[
AsyncFunctionDef( AsyncFunctionDef(
name='f', name='f',
type_params=[],
args=arguments( args=arguments(
posonlyargs=[], posonlyargs=[],
args=[], args=[],
@ -1901,7 +1900,8 @@ Async and await
func=Name(id='other_func', ctx=Load()), func=Name(id='other_func', ctx=Load()),
args=[], args=[],
keywords=[])))], keywords=[])))],
decorator_list=[])], decorator_list=[],
type_params=[])],
type_ignores=[]) type_ignores=[])

View File

@ -254,10 +254,10 @@ class_def[stmt_ty]:
class_def_raw[stmt_ty]: class_def_raw[stmt_ty]:
| invalid_class_def_raw | invalid_class_def_raw
| 'class' a=NAME t=[type_params] b=['(' z=[arguments] ')' { z }] ':' c=block { | 'class' a=NAME t=[type_params] b=['(' z=[arguments] ')' { z }] ':' c=block {
_PyAST_ClassDef(a->v.Name.id, t, _PyAST_ClassDef(a->v.Name.id,
(b) ? ((expr_ty) b)->v.Call.args : NULL, (b) ? ((expr_ty) b)->v.Call.args : NULL,
(b) ? ((expr_ty) b)->v.Call.keywords : NULL, (b) ? ((expr_ty) b)->v.Call.keywords : NULL,
c, NULL, EXTRA) } c, NULL, t, EXTRA) }
# Function definitions # Function definitions
# -------------------- # --------------------
@ -269,17 +269,17 @@ function_def[stmt_ty]:
function_def_raw[stmt_ty]: function_def_raw[stmt_ty]:
| invalid_def_raw | invalid_def_raw
| 'def' n=NAME t=[type_params] &&'(' params=[params] ')' a=['->' z=expression { z }] &&':' tc=[func_type_comment] b=block { | 'def' n=NAME t=[type_params] &&'(' params=[params] ')' a=['->' z=expression { z }] &&':' tc=[func_type_comment] b=block {
_PyAST_FunctionDef(n->v.Name.id, t, _PyAST_FunctionDef(n->v.Name.id,
(params) ? params : CHECK(arguments_ty, _PyPegen_empty_arguments(p)), (params) ? params : CHECK(arguments_ty, _PyPegen_empty_arguments(p)),
b, NULL, a, NEW_TYPE_COMMENT(p, tc), EXTRA) } b, NULL, a, NEW_TYPE_COMMENT(p, tc), t, EXTRA) }
| ASYNC 'def' n=NAME t=[type_params] &&'(' params=[params] ')' a=['->' z=expression { z }] &&':' tc=[func_type_comment] b=block { | ASYNC 'def' n=NAME t=[type_params] &&'(' params=[params] ')' a=['->' z=expression { z }] &&':' tc=[func_type_comment] b=block {
CHECK_VERSION( CHECK_VERSION(
stmt_ty, stmt_ty,
5, 5,
"Async functions are", "Async functions are",
_PyAST_AsyncFunctionDef(n->v.Name.id, t, _PyAST_AsyncFunctionDef(n->v.Name.id,
(params) ? params : CHECK(arguments_ty, _PyPegen_empty_arguments(p)), (params) ? params : CHECK(arguments_ty, _PyPegen_empty_arguments(p)),
b, NULL, a, NEW_TYPE_COMMENT(p, tc), EXTRA) b, NULL, a, NEW_TYPE_COMMENT(p, tc), t, EXTRA)
) } ) }
# Function parameters # Function parameters

View File

@ -198,31 +198,31 @@ struct _stmt {
union { union {
struct { struct {
identifier name; identifier name;
asdl_type_param_seq *type_params;
arguments_ty args; arguments_ty args;
asdl_stmt_seq *body; asdl_stmt_seq *body;
asdl_expr_seq *decorator_list; asdl_expr_seq *decorator_list;
expr_ty returns; expr_ty returns;
string type_comment; string type_comment;
asdl_type_param_seq *type_params;
} FunctionDef; } FunctionDef;
struct { struct {
identifier name; identifier name;
asdl_type_param_seq *type_params;
arguments_ty args; arguments_ty args;
asdl_stmt_seq *body; asdl_stmt_seq *body;
asdl_expr_seq *decorator_list; asdl_expr_seq *decorator_list;
expr_ty returns; expr_ty returns;
string type_comment; string type_comment;
asdl_type_param_seq *type_params;
} AsyncFunctionDef; } AsyncFunctionDef;
struct { struct {
identifier name; identifier name;
asdl_type_param_seq *type_params;
asdl_expr_seq *bases; asdl_expr_seq *bases;
asdl_keyword_seq *keywords; asdl_keyword_seq *keywords;
asdl_stmt_seq *body; asdl_stmt_seq *body;
asdl_expr_seq *decorator_list; asdl_expr_seq *decorator_list;
asdl_type_param_seq *type_params;
} ClassDef; } ClassDef;
struct { struct {
@ -682,22 +682,22 @@ mod_ty _PyAST_Interactive(asdl_stmt_seq * body, PyArena *arena);
mod_ty _PyAST_Expression(expr_ty body, PyArena *arena); mod_ty _PyAST_Expression(expr_ty body, PyArena *arena);
mod_ty _PyAST_FunctionType(asdl_expr_seq * argtypes, expr_ty returns, PyArena mod_ty _PyAST_FunctionType(asdl_expr_seq * argtypes, expr_ty returns, PyArena
*arena); *arena);
stmt_ty _PyAST_FunctionDef(identifier name, asdl_type_param_seq * type_params, stmt_ty _PyAST_FunctionDef(identifier name, arguments_ty args, asdl_stmt_seq *
arguments_ty args, asdl_stmt_seq * body, body, asdl_expr_seq * decorator_list, expr_ty
asdl_expr_seq * decorator_list, expr_ty returns, returns, string type_comment, asdl_type_param_seq *
string type_comment, int lineno, int col_offset, int type_params, int lineno, int col_offset, int
end_lineno, int end_col_offset, PyArena *arena); end_lineno, int end_col_offset, PyArena *arena);
stmt_ty _PyAST_AsyncFunctionDef(identifier name, asdl_type_param_seq * stmt_ty _PyAST_AsyncFunctionDef(identifier name, arguments_ty args,
type_params, arguments_ty args, asdl_stmt_seq * asdl_stmt_seq * body, asdl_expr_seq *
body, asdl_expr_seq * decorator_list, expr_ty decorator_list, expr_ty returns, string
returns, string type_comment, int lineno, int type_comment, asdl_type_param_seq *
col_offset, int end_lineno, int end_col_offset, type_params, int lineno, int col_offset, int
PyArena *arena); end_lineno, int end_col_offset, PyArena *arena);
stmt_ty _PyAST_ClassDef(identifier name, asdl_type_param_seq * type_params, stmt_ty _PyAST_ClassDef(identifier name, asdl_expr_seq * bases,
asdl_expr_seq * bases, asdl_keyword_seq * keywords, asdl_keyword_seq * keywords, asdl_stmt_seq * body,
asdl_stmt_seq * body, asdl_expr_seq * decorator_list, asdl_expr_seq * decorator_list, asdl_type_param_seq *
int lineno, int col_offset, int end_lineno, int type_params, int lineno, int col_offset, int
end_col_offset, PyArena *arena); end_lineno, int end_col_offset, PyArena *arena);
stmt_ty _PyAST_Return(expr_ty value, int lineno, int col_offset, int stmt_ty _PyAST_Return(expr_ty value, int lineno, int col_offset, int
end_lineno, int end_col_offset, PyArena *arena); end_lineno, int end_col_offset, PyArena *arena);
stmt_ty _PyAST_Delete(asdl_expr_seq * targets, int lineno, int col_offset, int stmt_ty _PyAST_Delete(asdl_expr_seq * targets, int lineno, int col_offset, int

View File

@ -4,6 +4,7 @@ import dis
import enum import enum
import os import os
import sys import sys
import textwrap
import types import types
import unittest import unittest
import warnings import warnings
@ -1583,20 +1584,41 @@ class ASTValidatorTests(unittest.TestCase):
def test_funcdef(self): def test_funcdef(self):
a = ast.arguments([], [], None, [], [], None, []) a = ast.arguments([], [], None, [], [], None, [])
f = ast.FunctionDef("x", [], a, [], [], None) f = ast.FunctionDef("x", a, [], [], None, None, [])
self.stmt(f, "empty body on FunctionDef") self.stmt(f, "empty body on FunctionDef")
f = ast.FunctionDef("x", [], a, [ast.Pass()], [ast.Name("x", ast.Store())], f = ast.FunctionDef("x", a, [ast.Pass()], [ast.Name("x", ast.Store())], None, None, [])
None)
self.stmt(f, "must have Load context") self.stmt(f, "must have Load context")
f = ast.FunctionDef("x", [], a, [ast.Pass()], [], f = ast.FunctionDef("x", a, [ast.Pass()], [],
ast.Name("x", ast.Store())) ast.Name("x", ast.Store()), None, [])
self.stmt(f, "must have Load context") self.stmt(f, "must have Load context")
def fac(args): def fac(args):
return ast.FunctionDef("x", [], args, [ast.Pass()], [], None) return ast.FunctionDef("x", args, [ast.Pass()], [], None, None, [])
self._check_arguments(fac, self.stmt) self._check_arguments(fac, self.stmt)
def test_funcdef_pattern_matching(self):
# gh-104799: New fields on FunctionDef should be added at the end
def matcher(node):
match node:
case ast.FunctionDef("foo", ast.arguments(args=[ast.arg("bar")]),
[ast.Pass()],
[ast.Name("capybara", ast.Load())],
ast.Name("pacarana", ast.Load())):
return True
case _:
return False
code = """
@capybara
def foo(bar) -> pacarana:
pass
"""
source = ast.parse(textwrap.dedent(code))
funcdef = source.body[0]
self.assertIsInstance(funcdef, ast.FunctionDef)
self.assertTrue(matcher(funcdef))
def test_classdef(self): def test_classdef(self):
def cls(bases=None, keywords=None, body=None, decorator_list=None): def cls(bases=None, keywords=None, body=None, decorator_list=None, type_params=None):
if bases is None: if bases is None:
bases = [] bases = []
if keywords is None: if keywords is None:
@ -1605,8 +1627,10 @@ class ASTValidatorTests(unittest.TestCase):
body = [ast.Pass()] body = [ast.Pass()]
if decorator_list is None: if decorator_list is None:
decorator_list = [] decorator_list = []
return ast.ClassDef("myclass", [], bases, keywords, if type_params is None:
body, decorator_list) type_params = []
return ast.ClassDef("myclass", bases, keywords,
body, decorator_list, type_params)
self.stmt(cls(bases=[ast.Name("x", ast.Store())]), self.stmt(cls(bases=[ast.Name("x", ast.Store())]),
"must have Load context") "must have Load context")
self.stmt(cls(keywords=[ast.keyword("x", ast.Name("x", ast.Store()))]), self.stmt(cls(keywords=[ast.keyword("x", ast.Name("x", ast.Store()))]),
@ -2895,23 +2919,23 @@ def main():
exec_results = [ exec_results = [
('Module', [('Expr', (1, 0, 1, 4), ('Constant', (1, 0, 1, 4), None, None))], []), ('Module', [('Expr', (1, 0, 1, 4), ('Constant', (1, 0, 1, 4), None, None))], []),
('Module', [('Expr', (1, 0, 1, 18), ('Constant', (1, 0, 1, 18), 'module docstring', None))], []), ('Module', [('Expr', (1, 0, 1, 18), ('Constant', (1, 0, 1, 18), 'module docstring', None))], []),
('Module', [('FunctionDef', (1, 0, 1, 13), 'f', [], ('arguments', [], [], None, [], [], None, []), [('Pass', (1, 9, 1, 13))], [], None, None)], []), ('Module', [('FunctionDef', (1, 0, 1, 13), 'f', ('arguments', [], [], None, [], [], None, []), [('Pass', (1, 9, 1, 13))], [], None, None, [])], []),
('Module', [('FunctionDef', (1, 0, 1, 29), 'f', [], ('arguments', [], [], None, [], [], None, []), [('Expr', (1, 9, 1, 29), ('Constant', (1, 9, 1, 29), 'function docstring', None))], [], None, None)], []), ('Module', [('FunctionDef', (1, 0, 1, 29), 'f', ('arguments', [], [], None, [], [], None, []), [('Expr', (1, 9, 1, 29), ('Constant', (1, 9, 1, 29), 'function docstring', None))], [], None, None, [])], []),
('Module', [('FunctionDef', (1, 0, 1, 14), 'f', [], ('arguments', [], [('arg', (1, 6, 1, 7), 'a', None, None)], None, [], [], None, []), [('Pass', (1, 10, 1, 14))], [], None, None)], []), ('Module', [('FunctionDef', (1, 0, 1, 14), 'f', ('arguments', [], [('arg', (1, 6, 1, 7), 'a', None, None)], None, [], [], None, []), [('Pass', (1, 10, 1, 14))], [], None, None, [])], []),
('Module', [('FunctionDef', (1, 0, 1, 16), 'f', [], ('arguments', [], [('arg', (1, 6, 1, 7), 'a', None, None)], None, [], [], None, [('Constant', (1, 8, 1, 9), 0, None)]), [('Pass', (1, 12, 1, 16))], [], None, None)], []), ('Module', [('FunctionDef', (1, 0, 1, 16), 'f', ('arguments', [], [('arg', (1, 6, 1, 7), 'a', None, None)], None, [], [], None, [('Constant', (1, 8, 1, 9), 0, None)]), [('Pass', (1, 12, 1, 16))], [], None, None, [])], []),
('Module', [('FunctionDef', (1, 0, 1, 18), 'f', [], ('arguments', [], [], ('arg', (1, 7, 1, 11), 'args', None, None), [], [], None, []), [('Pass', (1, 14, 1, 18))], [], None, None)], []), ('Module', [('FunctionDef', (1, 0, 1, 18), 'f', ('arguments', [], [], ('arg', (1, 7, 1, 11), 'args', None, None), [], [], None, []), [('Pass', (1, 14, 1, 18))], [], None, None, [])], []),
('Module', [('FunctionDef', (1, 0, 1, 23), 'f', [], ('arguments', [], [], ('arg', (1, 7, 1, 16), 'args', ('Starred', (1, 13, 1, 16), ('Name', (1, 14, 1, 16), 'Ts', ('Load',)), ('Load',)), None), [], [], None, []), [('Pass', (1, 19, 1, 23))], [], None, None)], []), ('Module', [('FunctionDef', (1, 0, 1, 23), 'f', ('arguments', [], [], ('arg', (1, 7, 1, 16), 'args', ('Starred', (1, 13, 1, 16), ('Name', (1, 14, 1, 16), 'Ts', ('Load',)), ('Load',)), None), [], [], None, []), [('Pass', (1, 19, 1, 23))], [], None, None, [])], []),
('Module', [('FunctionDef', (1, 0, 1, 36), 'f', [], ('arguments', [], [], ('arg', (1, 7, 1, 29), 'args', ('Starred', (1, 13, 1, 29), ('Subscript', (1, 14, 1, 29), ('Name', (1, 14, 1, 19), 'tuple', ('Load',)), ('Tuple', (1, 20, 1, 28), [('Name', (1, 20, 1, 23), 'int', ('Load',)), ('Constant', (1, 25, 1, 28), Ellipsis, None)], ('Load',)), ('Load',)), ('Load',)), None), [], [], None, []), [('Pass', (1, 32, 1, 36))], [], None, None)], []), ('Module', [('FunctionDef', (1, 0, 1, 36), 'f', ('arguments', [], [], ('arg', (1, 7, 1, 29), 'args', ('Starred', (1, 13, 1, 29), ('Subscript', (1, 14, 1, 29), ('Name', (1, 14, 1, 19), 'tuple', ('Load',)), ('Tuple', (1, 20, 1, 28), [('Name', (1, 20, 1, 23), 'int', ('Load',)), ('Constant', (1, 25, 1, 28), Ellipsis, None)], ('Load',)), ('Load',)), ('Load',)), None), [], [], None, []), [('Pass', (1, 32, 1, 36))], [], None, None, [])], []),
('Module', [('FunctionDef', (1, 0, 1, 36), 'f', [], ('arguments', [], [], ('arg', (1, 7, 1, 29), 'args', ('Starred', (1, 13, 1, 29), ('Subscript', (1, 14, 1, 29), ('Name', (1, 14, 1, 19), 'tuple', ('Load',)), ('Tuple', (1, 20, 1, 28), [('Name', (1, 20, 1, 23), 'int', ('Load',)), ('Starred', (1, 25, 1, 28), ('Name', (1, 26, 1, 28), 'Ts', ('Load',)), ('Load',))], ('Load',)), ('Load',)), ('Load',)), None), [], [], None, []), [('Pass', (1, 32, 1, 36))], [], None, None)], []), ('Module', [('FunctionDef', (1, 0, 1, 36), 'f', ('arguments', [], [], ('arg', (1, 7, 1, 29), 'args', ('Starred', (1, 13, 1, 29), ('Subscript', (1, 14, 1, 29), ('Name', (1, 14, 1, 19), 'tuple', ('Load',)), ('Tuple', (1, 20, 1, 28), [('Name', (1, 20, 1, 23), 'int', ('Load',)), ('Starred', (1, 25, 1, 28), ('Name', (1, 26, 1, 28), 'Ts', ('Load',)), ('Load',))], ('Load',)), ('Load',)), ('Load',)), None), [], [], None, []), [('Pass', (1, 32, 1, 36))], [], None, None, [])], []),
('Module', [('FunctionDef', (1, 0, 1, 21), 'f', [], ('arguments', [], [], None, [], [], ('arg', (1, 8, 1, 14), 'kwargs', None, None), []), [('Pass', (1, 17, 1, 21))], [], None, None)], []), ('Module', [('FunctionDef', (1, 0, 1, 21), 'f', ('arguments', [], [], None, [], [], ('arg', (1, 8, 1, 14), 'kwargs', None, None), []), [('Pass', (1, 17, 1, 21))], [], None, None, [])], []),
('Module', [('FunctionDef', (1, 0, 1, 71), 'f', [], ('arguments', [], [('arg', (1, 6, 1, 7), 'a', None, None), ('arg', (1, 9, 1, 10), 'b', None, None), ('arg', (1, 14, 1, 15), 'c', None, None), ('arg', (1, 22, 1, 23), 'd', None, None), ('arg', (1, 28, 1, 29), 'e', None, None)], ('arg', (1, 35, 1, 39), 'args', None, None), [('arg', (1, 41, 1, 42), 'f', None, None)], [('Constant', (1, 43, 1, 45), 42, None)], ('arg', (1, 49, 1, 55), 'kwargs', None, None), [('Constant', (1, 11, 1, 12), 1, None), ('Constant', (1, 16, 1, 20), None, None), ('List', (1, 24, 1, 26), [], ('Load',)), ('Dict', (1, 30, 1, 32), [], [])]), [('Expr', (1, 58, 1, 71), ('Constant', (1, 58, 1, 71), 'doc for f()', None))], [], None, None)], []), ('Module', [('FunctionDef', (1, 0, 1, 71), 'f', ('arguments', [], [('arg', (1, 6, 1, 7), 'a', None, None), ('arg', (1, 9, 1, 10), 'b', None, None), ('arg', (1, 14, 1, 15), 'c', None, None), ('arg', (1, 22, 1, 23), 'd', None, None), ('arg', (1, 28, 1, 29), 'e', None, None)], ('arg', (1, 35, 1, 39), 'args', None, None), [('arg', (1, 41, 1, 42), 'f', None, None)], [('Constant', (1, 43, 1, 45), 42, None)], ('arg', (1, 49, 1, 55), 'kwargs', None, None), [('Constant', (1, 11, 1, 12), 1, None), ('Constant', (1, 16, 1, 20), None, None), ('List', (1, 24, 1, 26), [], ('Load',)), ('Dict', (1, 30, 1, 32), [], [])]), [('Expr', (1, 58, 1, 71), ('Constant', (1, 58, 1, 71), 'doc for f()', None))], [], None, None, [])], []),
('Module', [('FunctionDef', (1, 0, 1, 27), 'f', [], ('arguments', [], [], None, [], [], None, []), [('Pass', (1, 23, 1, 27))], [], ('Subscript', (1, 11, 1, 21), ('Name', (1, 11, 1, 16), 'tuple', ('Load',)), ('Tuple', (1, 17, 1, 20), [('Starred', (1, 17, 1, 20), ('Name', (1, 18, 1, 20), 'Ts', ('Load',)), ('Load',))], ('Load',)), ('Load',)), None)], []), ('Module', [('FunctionDef', (1, 0, 1, 27), 'f', ('arguments', [], [], None, [], [], None, []), [('Pass', (1, 23, 1, 27))], [], ('Subscript', (1, 11, 1, 21), ('Name', (1, 11, 1, 16), 'tuple', ('Load',)), ('Tuple', (1, 17, 1, 20), [('Starred', (1, 17, 1, 20), ('Name', (1, 18, 1, 20), 'Ts', ('Load',)), ('Load',))], ('Load',)), ('Load',)), None, [])], []),
('Module', [('FunctionDef', (1, 0, 1, 32), 'f', [], ('arguments', [], [], None, [], [], None, []), [('Pass', (1, 28, 1, 32))], [], ('Subscript', (1, 11, 1, 26), ('Name', (1, 11, 1, 16), 'tuple', ('Load',)), ('Tuple', (1, 17, 1, 25), [('Name', (1, 17, 1, 20), 'int', ('Load',)), ('Starred', (1, 22, 1, 25), ('Name', (1, 23, 1, 25), 'Ts', ('Load',)), ('Load',))], ('Load',)), ('Load',)), None)], []), ('Module', [('FunctionDef', (1, 0, 1, 32), 'f', ('arguments', [], [], None, [], [], None, []), [('Pass', (1, 28, 1, 32))], [], ('Subscript', (1, 11, 1, 26), ('Name', (1, 11, 1, 16), 'tuple', ('Load',)), ('Tuple', (1, 17, 1, 25), [('Name', (1, 17, 1, 20), 'int', ('Load',)), ('Starred', (1, 22, 1, 25), ('Name', (1, 23, 1, 25), 'Ts', ('Load',)), ('Load',))], ('Load',)), ('Load',)), None, [])], []),
('Module', [('FunctionDef', (1, 0, 1, 45), 'f', [], ('arguments', [], [], None, [], [], None, []), [('Pass', (1, 41, 1, 45))], [], ('Subscript', (1, 11, 1, 39), ('Name', (1, 11, 1, 16), 'tuple', ('Load',)), ('Tuple', (1, 17, 1, 38), [('Name', (1, 17, 1, 20), 'int', ('Load',)), ('Starred', (1, 22, 1, 38), ('Subscript', (1, 23, 1, 38), ('Name', (1, 23, 1, 28), 'tuple', ('Load',)), ('Tuple', (1, 29, 1, 37), [('Name', (1, 29, 1, 32), 'int', ('Load',)), ('Constant', (1, 34, 1, 37), Ellipsis, None)], ('Load',)), ('Load',)), ('Load',))], ('Load',)), ('Load',)), None)], []), ('Module', [('FunctionDef', (1, 0, 1, 45), 'f', ('arguments', [], [], None, [], [], None, []), [('Pass', (1, 41, 1, 45))], [], ('Subscript', (1, 11, 1, 39), ('Name', (1, 11, 1, 16), 'tuple', ('Load',)), ('Tuple', (1, 17, 1, 38), [('Name', (1, 17, 1, 20), 'int', ('Load',)), ('Starred', (1, 22, 1, 38), ('Subscript', (1, 23, 1, 38), ('Name', (1, 23, 1, 28), 'tuple', ('Load',)), ('Tuple', (1, 29, 1, 37), [('Name', (1, 29, 1, 32), 'int', ('Load',)), ('Constant', (1, 34, 1, 37), Ellipsis, None)], ('Load',)), ('Load',)), ('Load',))], ('Load',)), ('Load',)), None, [])], []),
('Module', [('ClassDef', (1, 0, 1, 12), 'C', [], [], [], [('Pass', (1, 8, 1, 12))], [])], []), ('Module', [('ClassDef', (1, 0, 1, 12), 'C', [], [], [('Pass', (1, 8, 1, 12))], [], [])], []),
('Module', [('ClassDef', (1, 0, 1, 32), 'C', [], [], [], [('Expr', (1, 9, 1, 32), ('Constant', (1, 9, 1, 32), 'docstring for class C', None))], [])], []), ('Module', [('ClassDef', (1, 0, 1, 32), 'C', [], [], [('Expr', (1, 9, 1, 32), ('Constant', (1, 9, 1, 32), 'docstring for class C', None))], [], [])], []),
('Module', [('ClassDef', (1, 0, 1, 21), 'C', [], [('Name', (1, 8, 1, 14), 'object', ('Load',))], [], [('Pass', (1, 17, 1, 21))], [])], []), ('Module', [('ClassDef', (1, 0, 1, 21), 'C', [('Name', (1, 8, 1, 14), 'object', ('Load',))], [], [('Pass', (1, 17, 1, 21))], [], [])], []),
('Module', [('FunctionDef', (1, 0, 1, 16), 'f', [], ('arguments', [], [], None, [], [], None, []), [('Return', (1, 8, 1, 16), ('Constant', (1, 15, 1, 16), 1, None))], [], None, None)], []), ('Module', [('FunctionDef', (1, 0, 1, 16), 'f', ('arguments', [], [], None, [], [], None, []), [('Return', (1, 8, 1, 16), ('Constant', (1, 15, 1, 16), 1, None))], [], None, None, [])], []),
('Module', [('Delete', (1, 0, 1, 5), [('Name', (1, 4, 1, 5), 'v', ('Del',))])], []), ('Module', [('Delete', (1, 0, 1, 5), [('Name', (1, 4, 1, 5), 'v', ('Del',))])], []),
('Module', [('Assign', (1, 0, 1, 5), [('Name', (1, 0, 1, 1), 'v', ('Store',))], ('Constant', (1, 4, 1, 5), 1, None), None)], []), ('Module', [('Assign', (1, 0, 1, 5), [('Name', (1, 0, 1, 1), 'v', ('Store',))], ('Constant', (1, 4, 1, 5), 1, None), None)], []),
('Module', [('Assign', (1, 0, 1, 7), [('Tuple', (1, 0, 1, 3), [('Name', (1, 0, 1, 1), 'a', ('Store',)), ('Name', (1, 2, 1, 3), 'b', ('Store',))], ('Store',))], ('Name', (1, 6, 1, 7), 'c', ('Load',)), None)], []), ('Module', [('Assign', (1, 0, 1, 7), [('Tuple', (1, 0, 1, 3), [('Name', (1, 0, 1, 1), 'a', ('Store',)), ('Name', (1, 2, 1, 3), 'b', ('Store',))], ('Store',))], ('Name', (1, 6, 1, 7), 'c', ('Load',)), None)], []),
@ -2948,41 +2972,41 @@ exec_results = [
('Module', [('Expr', (1, 0, 1, 20), ('DictComp', (1, 0, 1, 20), ('Name', (1, 1, 1, 2), 'a', ('Load',)), ('Name', (1, 5, 1, 6), 'b', ('Load',)), [('comprehension', ('Tuple', (1, 11, 1, 14), [('Name', (1, 11, 1, 12), 'v', ('Store',)), ('Name', (1, 13, 1, 14), 'w', ('Store',))], ('Store',)), ('Name', (1, 18, 1, 19), 'x', ('Load',)), [], 0)]))], []), ('Module', [('Expr', (1, 0, 1, 20), ('DictComp', (1, 0, 1, 20), ('Name', (1, 1, 1, 2), 'a', ('Load',)), ('Name', (1, 5, 1, 6), 'b', ('Load',)), [('comprehension', ('Tuple', (1, 11, 1, 14), [('Name', (1, 11, 1, 12), 'v', ('Store',)), ('Name', (1, 13, 1, 14), 'w', ('Store',))], ('Store',)), ('Name', (1, 18, 1, 19), 'x', ('Load',)), [], 0)]))], []),
('Module', [('Expr', (1, 0, 1, 19), ('SetComp', (1, 0, 1, 19), ('Name', (1, 1, 1, 2), 'r', ('Load',)), [('comprehension', ('Name', (1, 7, 1, 8), 'l', ('Store',)), ('Name', (1, 12, 1, 13), 'x', ('Load',)), [('Name', (1, 17, 1, 18), 'g', ('Load',))], 0)]))], []), ('Module', [('Expr', (1, 0, 1, 19), ('SetComp', (1, 0, 1, 19), ('Name', (1, 1, 1, 2), 'r', ('Load',)), [('comprehension', ('Name', (1, 7, 1, 8), 'l', ('Store',)), ('Name', (1, 12, 1, 13), 'x', ('Load',)), [('Name', (1, 17, 1, 18), 'g', ('Load',))], 0)]))], []),
('Module', [('Expr', (1, 0, 1, 16), ('SetComp', (1, 0, 1, 16), ('Name', (1, 1, 1, 2), 'r', ('Load',)), [('comprehension', ('Tuple', (1, 7, 1, 10), [('Name', (1, 7, 1, 8), 'l', ('Store',)), ('Name', (1, 9, 1, 10), 'm', ('Store',))], ('Store',)), ('Name', (1, 14, 1, 15), 'x', ('Load',)), [], 0)]))], []), ('Module', [('Expr', (1, 0, 1, 16), ('SetComp', (1, 0, 1, 16), ('Name', (1, 1, 1, 2), 'r', ('Load',)), [('comprehension', ('Tuple', (1, 7, 1, 10), [('Name', (1, 7, 1, 8), 'l', ('Store',)), ('Name', (1, 9, 1, 10), 'm', ('Store',))], ('Store',)), ('Name', (1, 14, 1, 15), 'x', ('Load',)), [], 0)]))], []),
('Module', [('AsyncFunctionDef', (1, 0, 3, 18), 'f', [], ('arguments', [], [], None, [], [], None, []), [('Expr', (2, 1, 2, 17), ('Constant', (2, 1, 2, 17), 'async function', None)), ('Expr', (3, 1, 3, 18), ('Await', (3, 1, 3, 18), ('Call', (3, 7, 3, 18), ('Name', (3, 7, 3, 16), 'something', ('Load',)), [], [])))], [], None, None)], []), ('Module', [('AsyncFunctionDef', (1, 0, 3, 18), 'f', ('arguments', [], [], None, [], [], None, []), [('Expr', (2, 1, 2, 17), ('Constant', (2, 1, 2, 17), 'async function', None)), ('Expr', (3, 1, 3, 18), ('Await', (3, 1, 3, 18), ('Call', (3, 7, 3, 18), ('Name', (3, 7, 3, 16), 'something', ('Load',)), [], [])))], [], None, None, [])], []),
('Module', [('AsyncFunctionDef', (1, 0, 3, 8), 'f', [], ('arguments', [], [], None, [], [], None, []), [('AsyncFor', (2, 1, 3, 8), ('Name', (2, 11, 2, 12), 'e', ('Store',)), ('Name', (2, 16, 2, 17), 'i', ('Load',)), [('Expr', (2, 19, 2, 20), ('Constant', (2, 19, 2, 20), 1, None))], [('Expr', (3, 7, 3, 8), ('Constant', (3, 7, 3, 8), 2, None))], None)], [], None, None)], []), ('Module', [('AsyncFunctionDef', (1, 0, 3, 8), 'f', ('arguments', [], [], None, [], [], None, []), [('AsyncFor', (2, 1, 3, 8), ('Name', (2, 11, 2, 12), 'e', ('Store',)), ('Name', (2, 16, 2, 17), 'i', ('Load',)), [('Expr', (2, 19, 2, 20), ('Constant', (2, 19, 2, 20), 1, None))], [('Expr', (3, 7, 3, 8), ('Constant', (3, 7, 3, 8), 2, None))], None)], [], None, None, [])], []),
('Module', [('AsyncFunctionDef', (1, 0, 2, 21), 'f', [], ('arguments', [], [], None, [], [], None, []), [('AsyncWith', (2, 1, 2, 21), [('withitem', ('Name', (2, 12, 2, 13), 'a', ('Load',)), ('Name', (2, 17, 2, 18), 'b', ('Store',)))], [('Expr', (2, 20, 2, 21), ('Constant', (2, 20, 2, 21), 1, None))], None)], [], None, None)], []), ('Module', [('AsyncFunctionDef', (1, 0, 2, 21), 'f', ('arguments', [], [], None, [], [], None, []), [('AsyncWith', (2, 1, 2, 21), [('withitem', ('Name', (2, 12, 2, 13), 'a', ('Load',)), ('Name', (2, 17, 2, 18), 'b', ('Store',)))], [('Expr', (2, 20, 2, 21), ('Constant', (2, 20, 2, 21), 1, None))], None)], [], None, None, [])], []),
('Module', [('Expr', (1, 0, 1, 14), ('Dict', (1, 0, 1, 14), [None, ('Constant', (1, 10, 1, 11), 2, None)], [('Dict', (1, 3, 1, 8), [('Constant', (1, 4, 1, 5), 1, None)], [('Constant', (1, 6, 1, 7), 2, None)]), ('Constant', (1, 12, 1, 13), 3, None)]))], []), ('Module', [('Expr', (1, 0, 1, 14), ('Dict', (1, 0, 1, 14), [None, ('Constant', (1, 10, 1, 11), 2, None)], [('Dict', (1, 3, 1, 8), [('Constant', (1, 4, 1, 5), 1, None)], [('Constant', (1, 6, 1, 7), 2, None)]), ('Constant', (1, 12, 1, 13), 3, None)]))], []),
('Module', [('Expr', (1, 0, 1, 12), ('Set', (1, 0, 1, 12), [('Starred', (1, 1, 1, 8), ('Set', (1, 2, 1, 8), [('Constant', (1, 3, 1, 4), 1, None), ('Constant', (1, 6, 1, 7), 2, None)]), ('Load',)), ('Constant', (1, 10, 1, 11), 3, None)]))], []), ('Module', [('Expr', (1, 0, 1, 12), ('Set', (1, 0, 1, 12), [('Starred', (1, 1, 1, 8), ('Set', (1, 2, 1, 8), [('Constant', (1, 3, 1, 4), 1, None), ('Constant', (1, 6, 1, 7), 2, None)]), ('Load',)), ('Constant', (1, 10, 1, 11), 3, None)]))], []),
('Module', [('AsyncFunctionDef', (1, 0, 2, 21), 'f', [], ('arguments', [], [], None, [], [], None, []), [('Expr', (2, 1, 2, 21), ('ListComp', (2, 1, 2, 21), ('Name', (2, 2, 2, 3), 'i', ('Load',)), [('comprehension', ('Name', (2, 14, 2, 15), 'b', ('Store',)), ('Name', (2, 19, 2, 20), 'c', ('Load',)), [], 1)]))], [], None, None)], []), ('Module', [('AsyncFunctionDef', (1, 0, 2, 21), 'f', ('arguments', [], [], None, [], [], None, []), [('Expr', (2, 1, 2, 21), ('ListComp', (2, 1, 2, 21), ('Name', (2, 2, 2, 3), 'i', ('Load',)), [('comprehension', ('Name', (2, 14, 2, 15), 'b', ('Store',)), ('Name', (2, 19, 2, 20), 'c', ('Load',)), [], 1)]))], [], None, None, [])], []),
('Module', [('FunctionDef', (4, 0, 4, 13), 'f', [], ('arguments', [], [], None, [], [], None, []), [('Pass', (4, 9, 4, 13))], [('Name', (1, 1, 1, 6), 'deco1', ('Load',)), ('Call', (2, 1, 2, 8), ('Name', (2, 1, 2, 6), 'deco2', ('Load',)), [], []), ('Call', (3, 1, 3, 9), ('Name', (3, 1, 3, 6), 'deco3', ('Load',)), [('Constant', (3, 7, 3, 8), 1, None)], [])], None, None)], []), ('Module', [('FunctionDef', (4, 0, 4, 13), 'f', ('arguments', [], [], None, [], [], None, []), [('Pass', (4, 9, 4, 13))], [('Name', (1, 1, 1, 6), 'deco1', ('Load',)), ('Call', (2, 1, 2, 8), ('Name', (2, 1, 2, 6), 'deco2', ('Load',)), [], []), ('Call', (3, 1, 3, 9), ('Name', (3, 1, 3, 6), 'deco3', ('Load',)), [('Constant', (3, 7, 3, 8), 1, None)], [])], None, None, [])], []),
('Module', [('AsyncFunctionDef', (4, 0, 4, 19), 'f', [], ('arguments', [], [], None, [], [], None, []), [('Pass', (4, 15, 4, 19))], [('Name', (1, 1, 1, 6), 'deco1', ('Load',)), ('Call', (2, 1, 2, 8), ('Name', (2, 1, 2, 6), 'deco2', ('Load',)), [], []), ('Call', (3, 1, 3, 9), ('Name', (3, 1, 3, 6), 'deco3', ('Load',)), [('Constant', (3, 7, 3, 8), 1, None)], [])], None, None)], []), ('Module', [('AsyncFunctionDef', (4, 0, 4, 19), 'f', ('arguments', [], [], None, [], [], None, []), [('Pass', (4, 15, 4, 19))], [('Name', (1, 1, 1, 6), 'deco1', ('Load',)), ('Call', (2, 1, 2, 8), ('Name', (2, 1, 2, 6), 'deco2', ('Load',)), [], []), ('Call', (3, 1, 3, 9), ('Name', (3, 1, 3, 6), 'deco3', ('Load',)), [('Constant', (3, 7, 3, 8), 1, None)], [])], None, None, [])], []),
('Module', [('ClassDef', (4, 0, 4, 13), 'C', [], [], [], [('Pass', (4, 9, 4, 13))], [('Name', (1, 1, 1, 6), 'deco1', ('Load',)), ('Call', (2, 1, 2, 8), ('Name', (2, 1, 2, 6), 'deco2', ('Load',)), [], []), ('Call', (3, 1, 3, 9), ('Name', (3, 1, 3, 6), 'deco3', ('Load',)), [('Constant', (3, 7, 3, 8), 1, None)], [])])], []), ('Module', [('ClassDef', (4, 0, 4, 13), 'C', [], [], [('Pass', (4, 9, 4, 13))], [('Name', (1, 1, 1, 6), 'deco1', ('Load',)), ('Call', (2, 1, 2, 8), ('Name', (2, 1, 2, 6), 'deco2', ('Load',)), [], []), ('Call', (3, 1, 3, 9), ('Name', (3, 1, 3, 6), 'deco3', ('Load',)), [('Constant', (3, 7, 3, 8), 1, None)], [])], [])], []),
('Module', [('FunctionDef', (2, 0, 2, 13), 'f', [], ('arguments', [], [], None, [], [], None, []), [('Pass', (2, 9, 2, 13))], [('Call', (1, 1, 1, 19), ('Name', (1, 1, 1, 5), 'deco', ('Load',)), [('GeneratorExp', (1, 5, 1, 19), ('Name', (1, 6, 1, 7), 'a', ('Load',)), [('comprehension', ('Name', (1, 12, 1, 13), 'a', ('Store',)), ('Name', (1, 17, 1, 18), 'b', ('Load',)), [], 0)])], [])], None, None)], []), ('Module', [('FunctionDef', (2, 0, 2, 13), 'f', ('arguments', [], [], None, [], [], None, []), [('Pass', (2, 9, 2, 13))], [('Call', (1, 1, 1, 19), ('Name', (1, 1, 1, 5), 'deco', ('Load',)), [('GeneratorExp', (1, 5, 1, 19), ('Name', (1, 6, 1, 7), 'a', ('Load',)), [('comprehension', ('Name', (1, 12, 1, 13), 'a', ('Store',)), ('Name', (1, 17, 1, 18), 'b', ('Load',)), [], 0)])], [])], None, None, [])], []),
('Module', [('FunctionDef', (2, 0, 2, 13), 'f', [], ('arguments', [], [], None, [], [], None, []), [('Pass', (2, 9, 2, 13))], [('Attribute', (1, 1, 1, 6), ('Attribute', (1, 1, 1, 4), ('Name', (1, 1, 1, 2), 'a', ('Load',)), 'b', ('Load',)), 'c', ('Load',))], None, None)], []), ('Module', [('FunctionDef', (2, 0, 2, 13), 'f', ('arguments', [], [], None, [], [], None, []), [('Pass', (2, 9, 2, 13))], [('Attribute', (1, 1, 1, 6), ('Attribute', (1, 1, 1, 4), ('Name', (1, 1, 1, 2), 'a', ('Load',)), 'b', ('Load',)), 'c', ('Load',))], None, None, [])], []),
('Module', [('Expr', (1, 0, 1, 8), ('NamedExpr', (1, 1, 1, 7), ('Name', (1, 1, 1, 2), 'a', ('Store',)), ('Constant', (1, 6, 1, 7), 1, None)))], []), ('Module', [('Expr', (1, 0, 1, 8), ('NamedExpr', (1, 1, 1, 7), ('Name', (1, 1, 1, 2), 'a', ('Store',)), ('Constant', (1, 6, 1, 7), 1, None)))], []),
('Module', [('FunctionDef', (1, 0, 1, 18), 'f', [], ('arguments', [('arg', (1, 6, 1, 7), 'a', None, None)], [], None, [], [], None, []), [('Pass', (1, 14, 1, 18))], [], None, None)], []), ('Module', [('FunctionDef', (1, 0, 1, 18), 'f', ('arguments', [('arg', (1, 6, 1, 7), 'a', None, None)], [], None, [], [], None, []), [('Pass', (1, 14, 1, 18))], [], None, None, [])], []),
('Module', [('FunctionDef', (1, 0, 1, 26), 'f', [], ('arguments', [('arg', (1, 6, 1, 7), 'a', None, None)], [('arg', (1, 12, 1, 13), 'c', None, None), ('arg', (1, 15, 1, 16), 'd', None, None), ('arg', (1, 18, 1, 19), 'e', None, None)], None, [], [], None, []), [('Pass', (1, 22, 1, 26))], [], None, None)], []), ('Module', [('FunctionDef', (1, 0, 1, 26), 'f', ('arguments', [('arg', (1, 6, 1, 7), 'a', None, None)], [('arg', (1, 12, 1, 13), 'c', None, None), ('arg', (1, 15, 1, 16), 'd', None, None), ('arg', (1, 18, 1, 19), 'e', None, None)], None, [], [], None, []), [('Pass', (1, 22, 1, 26))], [], None, None, [])], []),
('Module', [('FunctionDef', (1, 0, 1, 29), 'f', [], ('arguments', [('arg', (1, 6, 1, 7), 'a', None, None)], [('arg', (1, 12, 1, 13), 'c', None, None)], None, [('arg', (1, 18, 1, 19), 'd', None, None), ('arg', (1, 21, 1, 22), 'e', None, None)], [None, None], None, []), [('Pass', (1, 25, 1, 29))], [], None, None)], []), ('Module', [('FunctionDef', (1, 0, 1, 29), 'f', ('arguments', [('arg', (1, 6, 1, 7), 'a', None, None)], [('arg', (1, 12, 1, 13), 'c', None, None)], None, [('arg', (1, 18, 1, 19), 'd', None, None), ('arg', (1, 21, 1, 22), 'e', None, None)], [None, None], None, []), [('Pass', (1, 25, 1, 29))], [], None, None, [])], []),
('Module', [('FunctionDef', (1, 0, 1, 39), 'f', [], ('arguments', [('arg', (1, 6, 1, 7), 'a', None, None)], [('arg', (1, 12, 1, 13), 'c', None, None)], None, [('arg', (1, 18, 1, 19), 'd', None, None), ('arg', (1, 21, 1, 22), 'e', None, None)], [None, None], ('arg', (1, 26, 1, 32), 'kwargs', None, None), []), [('Pass', (1, 35, 1, 39))], [], None, None)], []), ('Module', [('FunctionDef', (1, 0, 1, 39), 'f', ('arguments', [('arg', (1, 6, 1, 7), 'a', None, None)], [('arg', (1, 12, 1, 13), 'c', None, None)], None, [('arg', (1, 18, 1, 19), 'd', None, None), ('arg', (1, 21, 1, 22), 'e', None, None)], [None, None], ('arg', (1, 26, 1, 32), 'kwargs', None, None), []), [('Pass', (1, 35, 1, 39))], [], None, None, [])], []),
('Module', [('FunctionDef', (1, 0, 1, 20), 'f', [], ('arguments', [('arg', (1, 6, 1, 7), 'a', None, None)], [], None, [], [], None, [('Constant', (1, 8, 1, 9), 1, None)]), [('Pass', (1, 16, 1, 20))], [], None, None)], []), ('Module', [('FunctionDef', (1, 0, 1, 20), 'f', ('arguments', [('arg', (1, 6, 1, 7), 'a', None, None)], [], None, [], [], None, [('Constant', (1, 8, 1, 9), 1, None)]), [('Pass', (1, 16, 1, 20))], [], None, None, [])], []),
('Module', [('FunctionDef', (1, 0, 1, 29), 'f', [], ('arguments', [('arg', (1, 6, 1, 7), 'a', None, None)], [('arg', (1, 14, 1, 15), 'b', None, None), ('arg', (1, 19, 1, 20), 'c', None, None)], None, [], [], None, [('Constant', (1, 8, 1, 9), 1, None), ('Constant', (1, 16, 1, 17), 2, None), ('Constant', (1, 21, 1, 22), 4, None)]), [('Pass', (1, 25, 1, 29))], [], None, None)], []), ('Module', [('FunctionDef', (1, 0, 1, 29), 'f', ('arguments', [('arg', (1, 6, 1, 7), 'a', None, None)], [('arg', (1, 14, 1, 15), 'b', None, None), ('arg', (1, 19, 1, 20), 'c', None, None)], None, [], [], None, [('Constant', (1, 8, 1, 9), 1, None), ('Constant', (1, 16, 1, 17), 2, None), ('Constant', (1, 21, 1, 22), 4, None)]), [('Pass', (1, 25, 1, 29))], [], None, None, [])], []),
('Module', [('FunctionDef', (1, 0, 1, 32), 'f', [], ('arguments', [('arg', (1, 6, 1, 7), 'a', None, None)], [('arg', (1, 14, 1, 15), 'b', None, None)], None, [('arg', (1, 22, 1, 23), 'c', None, None)], [('Constant', (1, 24, 1, 25), 4, None)], None, [('Constant', (1, 8, 1, 9), 1, None), ('Constant', (1, 16, 1, 17), 2, None)]), [('Pass', (1, 28, 1, 32))], [], None, None)], []), ('Module', [('FunctionDef', (1, 0, 1, 32), 'f', ('arguments', [('arg', (1, 6, 1, 7), 'a', None, None)], [('arg', (1, 14, 1, 15), 'b', None, None)], None, [('arg', (1, 22, 1, 23), 'c', None, None)], [('Constant', (1, 24, 1, 25), 4, None)], None, [('Constant', (1, 8, 1, 9), 1, None), ('Constant', (1, 16, 1, 17), 2, None)]), [('Pass', (1, 28, 1, 32))], [], None, None, [])], []),
('Module', [('FunctionDef', (1, 0, 1, 30), 'f', [], ('arguments', [('arg', (1, 6, 1, 7), 'a', None, None)], [('arg', (1, 14, 1, 15), 'b', None, None)], None, [('arg', (1, 22, 1, 23), 'c', None, None)], [None], None, [('Constant', (1, 8, 1, 9), 1, None), ('Constant', (1, 16, 1, 17), 2, None)]), [('Pass', (1, 26, 1, 30))], [], None, None)], []), ('Module', [('FunctionDef', (1, 0, 1, 30), 'f', ('arguments', [('arg', (1, 6, 1, 7), 'a', None, None)], [('arg', (1, 14, 1, 15), 'b', None, None)], None, [('arg', (1, 22, 1, 23), 'c', None, None)], [None], None, [('Constant', (1, 8, 1, 9), 1, None), ('Constant', (1, 16, 1, 17), 2, None)]), [('Pass', (1, 26, 1, 30))], [], None, None, [])], []),
('Module', [('FunctionDef', (1, 0, 1, 42), 'f', [], ('arguments', [('arg', (1, 6, 1, 7), 'a', None, None)], [('arg', (1, 14, 1, 15), 'b', None, None)], None, [('arg', (1, 22, 1, 23), 'c', None, None)], [('Constant', (1, 24, 1, 25), 4, None)], ('arg', (1, 29, 1, 35), 'kwargs', None, None), [('Constant', (1, 8, 1, 9), 1, None), ('Constant', (1, 16, 1, 17), 2, None)]), [('Pass', (1, 38, 1, 42))], [], None, None)], []), ('Module', [('FunctionDef', (1, 0, 1, 42), 'f', ('arguments', [('arg', (1, 6, 1, 7), 'a', None, None)], [('arg', (1, 14, 1, 15), 'b', None, None)], None, [('arg', (1, 22, 1, 23), 'c', None, None)], [('Constant', (1, 24, 1, 25), 4, None)], ('arg', (1, 29, 1, 35), 'kwargs', None, None), [('Constant', (1, 8, 1, 9), 1, None), ('Constant', (1, 16, 1, 17), 2, None)]), [('Pass', (1, 38, 1, 42))], [], None, None, [])], []),
('Module', [('FunctionDef', (1, 0, 1, 40), 'f', [], ('arguments', [('arg', (1, 6, 1, 7), 'a', None, None)], [('arg', (1, 14, 1, 15), 'b', None, None)], None, [('arg', (1, 22, 1, 23), 'c', None, None)], [None], ('arg', (1, 27, 1, 33), 'kwargs', None, None), [('Constant', (1, 8, 1, 9), 1, None), ('Constant', (1, 16, 1, 17), 2, None)]), [('Pass', (1, 36, 1, 40))], [], None, None)], []), ('Module', [('FunctionDef', (1, 0, 1, 40), 'f', ('arguments', [('arg', (1, 6, 1, 7), 'a', None, None)], [('arg', (1, 14, 1, 15), 'b', None, None)], None, [('arg', (1, 22, 1, 23), 'c', None, None)], [None], ('arg', (1, 27, 1, 33), 'kwargs', None, None), [('Constant', (1, 8, 1, 9), 1, None), ('Constant', (1, 16, 1, 17), 2, None)]), [('Pass', (1, 36, 1, 40))], [], None, None, [])], []),
('Module', [('TypeAlias', (1, 0, 1, 12), ('Name', (1, 5, 1, 6), 'X', ('Store',)), [], ('Name', (1, 9, 1, 12), 'int', ('Load',)))], []), ('Module', [('TypeAlias', (1, 0, 1, 12), ('Name', (1, 5, 1, 6), 'X', ('Store',)), [], ('Name', (1, 9, 1, 12), 'int', ('Load',)))], []),
('Module', [('TypeAlias', (1, 0, 1, 15), ('Name', (1, 5, 1, 6), 'X', ('Store',)), [('TypeVar', (1, 7, 1, 8), 'T', None)], ('Name', (1, 12, 1, 15), 'int', ('Load',)))], []), ('Module', [('TypeAlias', (1, 0, 1, 15), ('Name', (1, 5, 1, 6), 'X', ('Store',)), [('TypeVar', (1, 7, 1, 8), 'T', None)], ('Name', (1, 12, 1, 15), 'int', ('Load',)))], []),
('Module', [('TypeAlias', (1, 0, 1, 32), ('Name', (1, 5, 1, 6), 'X', ('Store',)), [('TypeVar', (1, 7, 1, 8), 'T', None), ('TypeVarTuple', (1, 10, 1, 13), 'Ts'), ('ParamSpec', (1, 15, 1, 18), 'P')], ('Tuple', (1, 22, 1, 32), [('Name', (1, 23, 1, 24), 'T', ('Load',)), ('Name', (1, 26, 1, 28), 'Ts', ('Load',)), ('Name', (1, 30, 1, 31), 'P', ('Load',))], ('Load',)))], []), ('Module', [('TypeAlias', (1, 0, 1, 32), ('Name', (1, 5, 1, 6), 'X', ('Store',)), [('TypeVar', (1, 7, 1, 8), 'T', None), ('TypeVarTuple', (1, 10, 1, 13), 'Ts'), ('ParamSpec', (1, 15, 1, 18), 'P')], ('Tuple', (1, 22, 1, 32), [('Name', (1, 23, 1, 24), 'T', ('Load',)), ('Name', (1, 26, 1, 28), 'Ts', ('Load',)), ('Name', (1, 30, 1, 31), 'P', ('Load',))], ('Load',)))], []),
('Module', [('TypeAlias', (1, 0, 1, 37), ('Name', (1, 5, 1, 6), 'X', ('Store',)), [('TypeVar', (1, 7, 1, 13), 'T', ('Name', (1, 10, 1, 13), 'int', ('Load',))), ('TypeVarTuple', (1, 15, 1, 18), 'Ts'), ('ParamSpec', (1, 20, 1, 23), 'P')], ('Tuple', (1, 27, 1, 37), [('Name', (1, 28, 1, 29), 'T', ('Load',)), ('Name', (1, 31, 1, 33), 'Ts', ('Load',)), ('Name', (1, 35, 1, 36), 'P', ('Load',))], ('Load',)))], []), ('Module', [('TypeAlias', (1, 0, 1, 37), ('Name', (1, 5, 1, 6), 'X', ('Store',)), [('TypeVar', (1, 7, 1, 13), 'T', ('Name', (1, 10, 1, 13), 'int', ('Load',))), ('TypeVarTuple', (1, 15, 1, 18), 'Ts'), ('ParamSpec', (1, 20, 1, 23), 'P')], ('Tuple', (1, 27, 1, 37), [('Name', (1, 28, 1, 29), 'T', ('Load',)), ('Name', (1, 31, 1, 33), 'Ts', ('Load',)), ('Name', (1, 35, 1, 36), 'P', ('Load',))], ('Load',)))], []),
('Module', [('TypeAlias', (1, 0, 1, 44), ('Name', (1, 5, 1, 6), 'X', ('Store',)), [('TypeVar', (1, 7, 1, 20), 'T', ('Tuple', (1, 10, 1, 20), [('Name', (1, 11, 1, 14), 'int', ('Load',)), ('Name', (1, 16, 1, 19), 'str', ('Load',))], ('Load',))), ('TypeVarTuple', (1, 22, 1, 25), 'Ts'), ('ParamSpec', (1, 27, 1, 30), 'P')], ('Tuple', (1, 34, 1, 44), [('Name', (1, 35, 1, 36), 'T', ('Load',)), ('Name', (1, 38, 1, 40), 'Ts', ('Load',)), ('Name', (1, 42, 1, 43), 'P', ('Load',))], ('Load',)))], []), ('Module', [('TypeAlias', (1, 0, 1, 44), ('Name', (1, 5, 1, 6), 'X', ('Store',)), [('TypeVar', (1, 7, 1, 20), 'T', ('Tuple', (1, 10, 1, 20), [('Name', (1, 11, 1, 14), 'int', ('Load',)), ('Name', (1, 16, 1, 19), 'str', ('Load',))], ('Load',))), ('TypeVarTuple', (1, 22, 1, 25), 'Ts'), ('ParamSpec', (1, 27, 1, 30), 'P')], ('Tuple', (1, 34, 1, 44), [('Name', (1, 35, 1, 36), 'T', ('Load',)), ('Name', (1, 38, 1, 40), 'Ts', ('Load',)), ('Name', (1, 42, 1, 43), 'P', ('Load',))], ('Load',)))], []),
('Module', [('ClassDef', (1, 0, 1, 16), 'X', [('TypeVar', (1, 8, 1, 9), 'T', None)], [], [], [('Pass', (1, 12, 1, 16))], [])], []), ('Module', [('ClassDef', (1, 0, 1, 16), 'X', [], [], [('Pass', (1, 12, 1, 16))], [], [('TypeVar', (1, 8, 1, 9), 'T', None)])], []),
('Module', [('ClassDef', (1, 0, 1, 26), 'X', [('TypeVar', (1, 8, 1, 9), 'T', None), ('TypeVarTuple', (1, 11, 1, 14), 'Ts'), ('ParamSpec', (1, 16, 1, 19), 'P')], [], [], [('Pass', (1, 22, 1, 26))], [])], []), ('Module', [('ClassDef', (1, 0, 1, 26), 'X', [], [], [('Pass', (1, 22, 1, 26))], [], [('TypeVar', (1, 8, 1, 9), 'T', None), ('TypeVarTuple', (1, 11, 1, 14), 'Ts'), ('ParamSpec', (1, 16, 1, 19), 'P')])], []),
('Module', [('ClassDef', (1, 0, 1, 31), 'X', [('TypeVar', (1, 8, 1, 14), 'T', ('Name', (1, 11, 1, 14), 'int', ('Load',))), ('TypeVarTuple', (1, 16, 1, 19), 'Ts'), ('ParamSpec', (1, 21, 1, 24), 'P')], [], [], [('Pass', (1, 27, 1, 31))], [])], []), ('Module', [('ClassDef', (1, 0, 1, 31), 'X', [], [], [('Pass', (1, 27, 1, 31))], [], [('TypeVar', (1, 8, 1, 14), 'T', ('Name', (1, 11, 1, 14), 'int', ('Load',))), ('TypeVarTuple', (1, 16, 1, 19), 'Ts'), ('ParamSpec', (1, 21, 1, 24), 'P')])], []),
('Module', [('ClassDef', (1, 0, 1, 38), 'X', [('TypeVar', (1, 8, 1, 21), 'T', ('Tuple', (1, 11, 1, 21), [('Name', (1, 12, 1, 15), 'int', ('Load',)), ('Name', (1, 17, 1, 20), 'str', ('Load',))], ('Load',))), ('TypeVarTuple', (1, 23, 1, 26), 'Ts'), ('ParamSpec', (1, 28, 1, 31), 'P')], [], [], [('Pass', (1, 34, 1, 38))], [])], []), ('Module', [('ClassDef', (1, 0, 1, 38), 'X', [], [], [('Pass', (1, 34, 1, 38))], [], [('TypeVar', (1, 8, 1, 21), 'T', ('Tuple', (1, 11, 1, 21), [('Name', (1, 12, 1, 15), 'int', ('Load',)), ('Name', (1, 17, 1, 20), 'str', ('Load',))], ('Load',))), ('TypeVarTuple', (1, 23, 1, 26), 'Ts'), ('ParamSpec', (1, 28, 1, 31), 'P')])], []),
('Module', [('FunctionDef', (1, 0, 1, 16), 'f', [('TypeVar', (1, 6, 1, 7), 'T', None)], ('arguments', [], [], None, [], [], None, []), [('Pass', (1, 12, 1, 16))], [], None, None)], []), ('Module', [('FunctionDef', (1, 0, 1, 16), 'f', ('arguments', [], [], None, [], [], None, []), [('Pass', (1, 12, 1, 16))], [], None, None, [('TypeVar', (1, 6, 1, 7), 'T', None)])], []),
('Module', [('FunctionDef', (1, 0, 1, 26), 'f', [('TypeVar', (1, 6, 1, 7), 'T', None), ('TypeVarTuple', (1, 9, 1, 12), 'Ts'), ('ParamSpec', (1, 14, 1, 17), 'P')], ('arguments', [], [], None, [], [], None, []), [('Pass', (1, 22, 1, 26))], [], None, None)], []), ('Module', [('FunctionDef', (1, 0, 1, 26), 'f', ('arguments', [], [], None, [], [], None, []), [('Pass', (1, 22, 1, 26))], [], None, None, [('TypeVar', (1, 6, 1, 7), 'T', None), ('TypeVarTuple', (1, 9, 1, 12), 'Ts'), ('ParamSpec', (1, 14, 1, 17), 'P')])], []),
('Module', [('FunctionDef', (1, 0, 1, 31), 'f', [('TypeVar', (1, 6, 1, 12), 'T', ('Name', (1, 9, 1, 12), 'int', ('Load',))), ('TypeVarTuple', (1, 14, 1, 17), 'Ts'), ('ParamSpec', (1, 19, 1, 22), 'P')], ('arguments', [], [], None, [], [], None, []), [('Pass', (1, 27, 1, 31))], [], None, None)], []), ('Module', [('FunctionDef', (1, 0, 1, 31), 'f', ('arguments', [], [], None, [], [], None, []), [('Pass', (1, 27, 1, 31))], [], None, None, [('TypeVar', (1, 6, 1, 12), 'T', ('Name', (1, 9, 1, 12), 'int', ('Load',))), ('TypeVarTuple', (1, 14, 1, 17), 'Ts'), ('ParamSpec', (1, 19, 1, 22), 'P')])], []),
('Module', [('FunctionDef', (1, 0, 1, 38), 'f', [('TypeVar', (1, 6, 1, 19), 'T', ('Tuple', (1, 9, 1, 19), [('Name', (1, 10, 1, 13), 'int', ('Load',)), ('Name', (1, 15, 1, 18), 'str', ('Load',))], ('Load',))), ('TypeVarTuple', (1, 21, 1, 24), 'Ts'), ('ParamSpec', (1, 26, 1, 29), 'P')], ('arguments', [], [], None, [], [], None, []), [('Pass', (1, 34, 1, 38))], [], None, None)], []), ('Module', [('FunctionDef', (1, 0, 1, 38), 'f', ('arguments', [], [], None, [], [], None, []), [('Pass', (1, 34, 1, 38))], [], None, None, [('TypeVar', (1, 6, 1, 19), 'T', ('Tuple', (1, 9, 1, 19), [('Name', (1, 10, 1, 13), 'int', ('Load',)), ('Name', (1, 15, 1, 18), 'str', ('Load',))], ('Load',))), ('TypeVarTuple', (1, 21, 1, 24), 'Ts'), ('ParamSpec', (1, 26, 1, 29), 'P')])], []),
] ]
single_results = [ single_results = [
('Interactive', [('Expr', (1, 0, 1, 3), ('BinOp', (1, 0, 1, 3), ('Constant', (1, 0, 1, 1), 1, None), ('Add',), ('Constant', (1, 2, 1, 3), 2, None)))]), ('Interactive', [('Expr', (1, 0, 1, 3), ('BinOp', (1, 0, 1, 3), ('Constant', (1, 0, 1, 1), 1, None), ('Add',), ('Constant', (1, 2, 1, 3), 2, None)))]),

View File

@ -0,0 +1,4 @@
Adjust the location of the (see :pep:`695`) ``type_params`` field on
:class:`ast.ClassDef`, :class:`ast.AsyncFunctionDef`, and
:class:`ast.FunctionDef` to better preserve backward compatibility. Patch by
Jelle Zijlstra

View File

@ -8,19 +8,19 @@ module Python
| Expression(expr body) | Expression(expr body)
| FunctionType(expr* argtypes, expr returns) | 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, stmt* body, expr* decorator_list, expr? returns,
string? type_comment) string? type_comment, type_param* type_params)
| AsyncFunctionDef(identifier name, type_param* type_params, arguments args, | AsyncFunctionDef(identifier name, arguments args,
stmt* body, expr* decorator_list, expr? returns, stmt* body, expr* decorator_list, expr? returns,
string? type_comment) string? type_comment, type_param* type_params)
| ClassDef(identifier name, | ClassDef(identifier name,
type_param* type_params,
expr* bases, expr* bases,
keyword* keywords, keyword* keywords,
stmt* body, stmt* body,
expr* decorator_list) expr* decorator_list,
type_param* type_params)
| Return(expr? value) | Return(expr? value)
| Delete(expr* targets) | 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); assert(function_def != NULL);
if (function_def->kind == AsyncFunctionDef_kind) { if (function_def->kind == AsyncFunctionDef_kind) {
return _PyAST_AsyncFunctionDef( return _PyAST_AsyncFunctionDef(
function_def->v.FunctionDef.name, function_def->v.FunctionDef.type_params, function_def->v.AsyncFunctionDef.name,
function_def->v.FunctionDef.args, function_def->v.AsyncFunctionDef.args,
function_def->v.FunctionDef.body, decorators, function_def->v.FunctionDef.returns, function_def->v.AsyncFunctionDef.body, decorators,
function_def->v.FunctionDef.type_comment, function_def->lineno, function_def->v.AsyncFunctionDef.returns,
function_def->col_offset, function_def->end_lineno, function_def->end_col_offset, function_def->v.AsyncFunctionDef.type_comment,
p->arena); 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( 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.args,
function_def->v.FunctionDef.body, decorators, function_def->v.FunctionDef.body, decorators,
function_def->v.FunctionDef.returns, function_def->v.FunctionDef.returns,
function_def->v.FunctionDef.type_comment, function_def->lineno, function_def->v.FunctionDef.type_comment,
function_def->col_offset, function_def->end_lineno, function_def->v.FunctionDef.type_params,
function_def->end_col_offset, p->arena); 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 */ /* 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); assert(class_def != NULL);
return _PyAST_ClassDef( 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.bases, class_def->v.ClassDef.keywords,
class_def->v.ClassDef.body, decorators, 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->lineno, class_def->col_offset, class_def->end_lineno,
class_def->end_col_offset, p->arena); 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 UNUSED(_end_lineno); // Only used by EXTRA macro
int _end_col_offset = _token->end_col_offset; int _end_col_offset = _token->end_col_offset;
UNUSED(_end_col_offset); // Only used by EXTRA macro 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()) { if (_res == NULL && PyErr_Occurred()) {
p->error_indicator = 1; p->error_indicator = 1;
p->level--; p->level--;
@ -4602,7 +4602,7 @@ function_def_raw_rule(Parser *p)
UNUSED(_end_lineno); // Only used by EXTRA macro UNUSED(_end_lineno); // Only used by EXTRA macro
int _end_col_offset = _token->end_col_offset; int _end_col_offset = _token->end_col_offset;
UNUSED(_end_col_offset); // Only used by EXTRA macro 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()) { if (_res == NULL && PyErr_Occurred()) {
p->error_indicator = 1; p->error_indicator = 1;
p->level--; p->level--;
@ -4665,7 +4665,7 @@ function_def_raw_rule(Parser *p)
UNUSED(_end_lineno); // Only used by EXTRA macro UNUSED(_end_lineno); // Only used by EXTRA macro
int _end_col_offset = _token->end_col_offset; int _end_col_offset = _token->end_col_offset;
UNUSED(_end_col_offset); // Only used by EXTRA macro 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()) { if (_res == NULL && PyErr_Occurred()) {
p->error_indicator = 1; p->error_indicator = 1;
p->level--; p->level--;

325
Python/Python-ast.c generated
View File

@ -409,29 +409,29 @@ static const char * const stmt_attributes[] = {
static PyObject* ast2obj_stmt(struct ast_state *state, void*); static PyObject* ast2obj_stmt(struct ast_state *state, void*);
static const char * const FunctionDef_fields[]={ static const char * const FunctionDef_fields[]={
"name", "name",
"type_params",
"args", "args",
"body", "body",
"decorator_list", "decorator_list",
"returns", "returns",
"type_comment", "type_comment",
"type_params",
}; };
static const char * const AsyncFunctionDef_fields[]={ static const char * const AsyncFunctionDef_fields[]={
"name", "name",
"type_params",
"args", "args",
"body", "body",
"decorator_list", "decorator_list",
"returns", "returns",
"type_comment", "type_comment",
"type_params",
}; };
static const char * const ClassDef_fields[]={ static const char * const ClassDef_fields[]={
"name", "name",
"type_params",
"bases", "bases",
"keywords", "keywords",
"body", "body",
"decorator_list", "decorator_list",
"type_params",
}; };
static const char * const Return_fields[]={ static const char * const Return_fields[]={
"value", "value",
@ -1169,9 +1169,9 @@ init_types(struct ast_state *state)
"FunctionType(expr* argtypes, expr returns)"); "FunctionType(expr* argtypes, expr returns)");
if (!state->FunctionType_type) return 0; if (!state->FunctionType_type) return 0;
state->stmt_type = make_type(state, "stmt", state->AST_type, NULL, 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" "stmt = FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment, type_param* type_params)\n"
" | AsyncFunctionDef(identifier name, type_param* type_params, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n" " | AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment, type_param* type_params)\n"
" | ClassDef(identifier name, type_param* type_params, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)\n" " | ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list, type_param* type_params)\n"
" | Return(expr? value)\n" " | Return(expr? value)\n"
" | Delete(expr* targets)\n" " | Delete(expr* targets)\n"
" | Assign(expr* targets, expr value, string? type_comment)\n" " | Assign(expr* targets, expr value, string? type_comment)\n"
@ -1206,7 +1206,7 @@ init_types(struct ast_state *state)
return 0; return 0;
state->FunctionDef_type = make_type(state, "FunctionDef", state->stmt_type, state->FunctionDef_type = make_type(state, "FunctionDef", state->stmt_type,
FunctionDef_fields, 7, 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 (!state->FunctionDef_type) return 0;
if (PyObject_SetAttr(state->FunctionDef_type, state->returns, Py_None) == if (PyObject_SetAttr(state->FunctionDef_type, state->returns, Py_None) ==
-1) -1)
@ -1217,7 +1217,7 @@ init_types(struct ast_state *state)
state->AsyncFunctionDef_type = make_type(state, "AsyncFunctionDef", state->AsyncFunctionDef_type = make_type(state, "AsyncFunctionDef",
state->stmt_type, state->stmt_type,
AsyncFunctionDef_fields, 7, 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 (!state->AsyncFunctionDef_type) return 0;
if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->returns, Py_None) if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->returns, Py_None)
== -1) == -1)
@ -1227,7 +1227,7 @@ init_types(struct ast_state *state)
return 0; return 0;
state->ClassDef_type = make_type(state, "ClassDef", state->stmt_type, state->ClassDef_type = make_type(state, "ClassDef", state->stmt_type,
ClassDef_fields, 6, 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; if (!state->ClassDef_type) return 0;
state->Return_type = make_type(state, "Return", state->stmt_type, state->Return_type = make_type(state, "Return", state->stmt_type,
Return_fields, 1, Return_fields, 1,
@ -2032,11 +2032,11 @@ _PyAST_FunctionType(asdl_expr_seq * argtypes, expr_ty returns, PyArena *arena)
} }
stmt_ty stmt_ty
_PyAST_FunctionDef(identifier name, asdl_type_param_seq * type_params, _PyAST_FunctionDef(identifier name, arguments_ty args, asdl_stmt_seq * body,
arguments_ty args, asdl_stmt_seq * body, asdl_expr_seq * asdl_expr_seq * decorator_list, expr_ty returns, string
decorator_list, expr_ty returns, string type_comment, int type_comment, asdl_type_param_seq * type_params, int lineno,
lineno, int col_offset, int end_lineno, int end_col_offset, int col_offset, int end_lineno, int end_col_offset, PyArena
PyArena *arena) *arena)
{ {
stmt_ty p; stmt_ty p;
if (!name) { if (!name) {
@ -2054,12 +2054,12 @@ _PyAST_FunctionDef(identifier name, asdl_type_param_seq * type_params,
return NULL; return NULL;
p->kind = FunctionDef_kind; p->kind = FunctionDef_kind;
p->v.FunctionDef.name = name; p->v.FunctionDef.name = name;
p->v.FunctionDef.type_params = type_params;
p->v.FunctionDef.args = args; p->v.FunctionDef.args = args;
p->v.FunctionDef.body = body; p->v.FunctionDef.body = body;
p->v.FunctionDef.decorator_list = decorator_list; p->v.FunctionDef.decorator_list = decorator_list;
p->v.FunctionDef.returns = returns; p->v.FunctionDef.returns = returns;
p->v.FunctionDef.type_comment = type_comment; p->v.FunctionDef.type_comment = type_comment;
p->v.FunctionDef.type_params = type_params;
p->lineno = lineno; p->lineno = lineno;
p->col_offset = col_offset; p->col_offset = col_offset;
p->end_lineno = end_lineno; p->end_lineno = end_lineno;
@ -2068,9 +2068,9 @@ _PyAST_FunctionDef(identifier name, asdl_type_param_seq * type_params,
} }
stmt_ty stmt_ty
_PyAST_AsyncFunctionDef(identifier name, asdl_type_param_seq * type_params, _PyAST_AsyncFunctionDef(identifier name, arguments_ty args, asdl_stmt_seq *
arguments_ty args, asdl_stmt_seq * body, asdl_expr_seq body, asdl_expr_seq * decorator_list, expr_ty returns,
* decorator_list, expr_ty returns, string type_comment, string type_comment, asdl_type_param_seq * type_params,
int lineno, int col_offset, int end_lineno, int int lineno, int col_offset, int end_lineno, int
end_col_offset, PyArena *arena) end_col_offset, PyArena *arena)
{ {
@ -2090,12 +2090,12 @@ _PyAST_AsyncFunctionDef(identifier name, asdl_type_param_seq * type_params,
return NULL; return NULL;
p->kind = AsyncFunctionDef_kind; p->kind = AsyncFunctionDef_kind;
p->v.AsyncFunctionDef.name = name; p->v.AsyncFunctionDef.name = name;
p->v.AsyncFunctionDef.type_params = type_params;
p->v.AsyncFunctionDef.args = args; p->v.AsyncFunctionDef.args = args;
p->v.AsyncFunctionDef.body = body; p->v.AsyncFunctionDef.body = body;
p->v.AsyncFunctionDef.decorator_list = decorator_list; p->v.AsyncFunctionDef.decorator_list = decorator_list;
p->v.AsyncFunctionDef.returns = returns; p->v.AsyncFunctionDef.returns = returns;
p->v.AsyncFunctionDef.type_comment = type_comment; p->v.AsyncFunctionDef.type_comment = type_comment;
p->v.AsyncFunctionDef.type_params = type_params;
p->lineno = lineno; p->lineno = lineno;
p->col_offset = col_offset; p->col_offset = col_offset;
p->end_lineno = end_lineno; p->end_lineno = end_lineno;
@ -2104,11 +2104,10 @@ _PyAST_AsyncFunctionDef(identifier name, asdl_type_param_seq * type_params,
} }
stmt_ty stmt_ty
_PyAST_ClassDef(identifier name, asdl_type_param_seq * type_params, _PyAST_ClassDef(identifier name, asdl_expr_seq * bases, asdl_keyword_seq *
asdl_expr_seq * bases, asdl_keyword_seq * keywords, keywords, asdl_stmt_seq * body, asdl_expr_seq * decorator_list,
asdl_stmt_seq * body, asdl_expr_seq * decorator_list, int asdl_type_param_seq * type_params, int lineno, int col_offset,
lineno, int col_offset, int end_lineno, int end_col_offset, int end_lineno, int end_col_offset, PyArena *arena)
PyArena *arena)
{ {
stmt_ty p; stmt_ty p;
if (!name) { if (!name) {
@ -2121,11 +2120,11 @@ _PyAST_ClassDef(identifier name, asdl_type_param_seq * type_params,
return NULL; return NULL;
p->kind = ClassDef_kind; p->kind = ClassDef_kind;
p->v.ClassDef.name = name; p->v.ClassDef.name = name;
p->v.ClassDef.type_params = type_params;
p->v.ClassDef.bases = bases; p->v.ClassDef.bases = bases;
p->v.ClassDef.keywords = keywords; p->v.ClassDef.keywords = keywords;
p->v.ClassDef.body = body; p->v.ClassDef.body = body;
p->v.ClassDef.decorator_list = decorator_list; p->v.ClassDef.decorator_list = decorator_list;
p->v.ClassDef.type_params = type_params;
p->lineno = lineno; p->lineno = lineno;
p->col_offset = col_offset; p->col_offset = col_offset;
p->end_lineno = end_lineno; 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) if (PyObject_SetAttr(result, state->name, value) == -1)
goto failed; goto failed;
Py_DECREF(value); 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); value = ast2obj_arguments(state, o->v.FunctionDef.args);
if (!value) goto failed; if (!value) goto failed;
if (PyObject_SetAttr(result, state->args, value) == -1) 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) if (PyObject_SetAttr(result, state->type_comment, value) == -1)
goto failed; goto failed;
Py_DECREF(value); 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; break;
case AsyncFunctionDef_kind: case AsyncFunctionDef_kind:
tp = (PyTypeObject *)state->AsyncFunctionDef_type; 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) if (PyObject_SetAttr(result, state->name, value) == -1)
goto failed; goto failed;
Py_DECREF(value); 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); value = ast2obj_arguments(state, o->v.AsyncFunctionDef.args);
if (!value) goto failed; if (!value) goto failed;
if (PyObject_SetAttr(result, state->args, value) == -1) 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) if (PyObject_SetAttr(result, state->type_comment, value) == -1)
goto failed; goto failed;
Py_DECREF(value); 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; break;
case ClassDef_kind: case ClassDef_kind:
tp = (PyTypeObject *)state->ClassDef_type; 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) if (PyObject_SetAttr(result, state->name, value) == -1)
goto failed; goto failed;
Py_DECREF(value); 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, value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.bases,
ast2obj_expr); ast2obj_expr);
if (!value) goto failed; 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) if (PyObject_SetAttr(result, state->decorator_list, value) == -1)
goto failed; goto failed;
Py_DECREF(value); 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; break;
case Return_kind: case Return_kind:
tp = (PyTypeObject *)state->Return_type; tp = (PyTypeObject *)state->Return_type;
@ -6075,12 +6074,12 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena*
} }
if (isinstance) { if (isinstance) {
identifier name; identifier name;
asdl_type_param_seq* type_params;
arguments_ty args; arguments_ty args;
asdl_stmt_seq* body; asdl_stmt_seq* body;
asdl_expr_seq* decorator_list; asdl_expr_seq* decorator_list;
expr_ty returns; expr_ty returns;
string type_comment; string type_comment;
asdl_type_param_seq* type_params;
if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) { if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
return 1; return 1;
@ -6099,42 +6098,6 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena*
if (res != 0) goto failed; if (res != 0) goto failed;
Py_CLEAR(tmp); 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) { if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
return 1; return 1;
} }
@ -6258,10 +6221,46 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena*
if (res != 0) goto failed; if (res != 0) goto failed;
Py_CLEAR(tmp); Py_CLEAR(tmp);
} }
*out = _PyAST_FunctionDef(name, type_params, args, body, if (_PyObject_LookupAttr(obj, state->type_params, &tmp) < 0) {
decorator_list, returns, type_comment, return 1;
lineno, col_offset, end_lineno, }
end_col_offset, arena); 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; if (*out == NULL) goto failed;
return 0; return 0;
} }
@ -6272,12 +6271,12 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena*
} }
if (isinstance) { if (isinstance) {
identifier name; identifier name;
asdl_type_param_seq* type_params;
arguments_ty args; arguments_ty args;
asdl_stmt_seq* body; asdl_stmt_seq* body;
asdl_expr_seq* decorator_list; asdl_expr_seq* decorator_list;
expr_ty returns; expr_ty returns;
string type_comment; string type_comment;
asdl_type_param_seq* type_params;
if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) { if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
return 1; return 1;
@ -6296,42 +6295,6 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena*
if (res != 0) goto failed; if (res != 0) goto failed;
Py_CLEAR(tmp); 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) { if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
return 1; return 1;
} }
@ -6455,8 +6418,44 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena*
if (res != 0) goto failed; if (res != 0) goto failed;
Py_CLEAR(tmp); Py_CLEAR(tmp);
} }
*out = _PyAST_AsyncFunctionDef(name, type_params, args, body, if (_PyObject_LookupAttr(obj, state->type_params, &tmp) < 0) {
decorator_list, returns, type_comment, 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, lineno, col_offset, end_lineno,
end_col_offset, arena); end_col_offset, arena);
if (*out == NULL) goto failed; if (*out == NULL) goto failed;
@ -6469,11 +6468,11 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena*
} }
if (isinstance) { if (isinstance) {
identifier name; identifier name;
asdl_type_param_seq* type_params;
asdl_expr_seq* bases; asdl_expr_seq* bases;
asdl_keyword_seq* keywords; asdl_keyword_seq* keywords;
asdl_stmt_seq* body; asdl_stmt_seq* body;
asdl_expr_seq* decorator_list; asdl_expr_seq* decorator_list;
asdl_type_param_seq* type_params;
if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) { if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
return 1; return 1;
@ -6492,42 +6491,6 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena*
if (res != 0) goto failed; if (res != 0) goto failed;
Py_CLEAR(tmp); 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) { if (_PyObject_LookupAttr(obj, state->bases, &tmp) < 0) {
return 1; return 1;
} }
@ -6672,8 +6635,44 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena*
} }
Py_CLEAR(tmp); Py_CLEAR(tmp);
} }
*out = _PyAST_ClassDef(name, type_params, bases, keywords, body, if (_PyObject_LookupAttr(obj, state->type_params, &tmp) < 0) {
decorator_list, lineno, col_offset, end_lineno, 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); end_col_offset, arena);
if (*out == NULL) goto failed; if (*out == NULL) goto failed;
return 0; return 0;