Skip to content

Commit a5f244d

Browse files
gh-104656: Rename typeparams AST node to type_params (#104657)
1 parent ef5d00a commit a5f244d

File tree

14 files changed

+290
-287
lines changed

14 files changed

+290
-287
lines changed

Doc/library/ast.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,7 +1724,7 @@ Function and class definitions
17241724
body=[
17251725
FunctionDef(
17261726
name='f',
1727-
typeparams=[],
1727+
type_params=[],
17281728
args=arguments(
17291729
posonlyargs=[],
17301730
args=[
@@ -1848,7 +1848,7 @@ Function and class definitions
18481848
body=[
18491849
ClassDef(
18501850
name='Foo',
1851-
typeparams=[],
1851+
type_params=[],
18521852
bases=[
18531853
Name(id='base1', ctx=Load()),
18541854
Name(id='base2', ctx=Load())],
@@ -1887,7 +1887,7 @@ Async and await
18871887
body=[
18881888
AsyncFunctionDef(
18891889
name='f',
1890-
typeparams=[],
1890+
type_params=[],
18911891
args=arguments(
18921892
posonlyargs=[],
18931893
args=[],

Grammar/python.gram

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -640,12 +640,12 @@ type_alias[stmt_ty]:
640640
# Type parameter declaration
641641
# --------------------------
642642

643-
type_params[asdl_typeparam_seq*]: '[' t=type_param_seq ']' {
644-
CHECK_VERSION(asdl_typeparam_seq *, 12, "Type parameter lists are", t) }
643+
type_params[asdl_type_param_seq*]: '[' t=type_param_seq ']' {
644+
CHECK_VERSION(asdl_type_param_seq *, 12, "Type parameter lists are", t) }
645645

646-
type_param_seq[asdl_typeparam_seq*]: a[asdl_typeparam_seq*]=','.type_param+ [','] { a }
646+
type_param_seq[asdl_type_param_seq*]: a[asdl_type_param_seq*]=','.type_param+ [','] { a }
647647

648-
type_param[typeparam_ty] (memo):
648+
type_param[type_param_ty] (memo):
649649
| a=NAME b=[type_param_bound] { _PyAST_TypeVar(a->v.Name.id, b, EXTRA) }
650650
| '*' a=NAME colon=":" e=expression {
651651
RAISE_SYNTAX_ERROR_STARTING_FROM(colon, e->kind == Tuple_kind

Include/internal/pycore_ast.h

Lines changed: 27 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_ast_state.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/ast.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ def visit_ClassDef(self, node):
10511051
self.fill("@")
10521052
self.traverse(deco)
10531053
self.fill("class " + node.name)
1054-
self._typeparams_helper(node.typeparams)
1054+
self._type_params_helper(node.type_params)
10551055
with self.delimit_if("(", ")", condition = node.bases or node.keywords):
10561056
comma = False
10571057
for e in node.bases:
@@ -1083,7 +1083,7 @@ def _function_helper(self, node, fill_suffix):
10831083
self.traverse(deco)
10841084
def_str = fill_suffix + " " + node.name
10851085
self.fill(def_str)
1086-
self._typeparams_helper(node.typeparams)
1086+
self._type_params_helper(node.type_params)
10871087
with self.delimit("(", ")"):
10881088
self.traverse(node.args)
10891089
if node.returns:
@@ -1092,10 +1092,10 @@ def _function_helper(self, node, fill_suffix):
10921092
with self.block(extra=self.get_type_comment(node)):
10931093
self._write_docstring_and_traverse_body(node)
10941094

1095-
def _typeparams_helper(self, typeparams):
1096-
if typeparams is not None and len(typeparams) > 0:
1095+
def _type_params_helper(self, type_params):
1096+
if type_params is not None and len(type_params) > 0:
10971097
with self.delimit("[", "]"):
1098-
self.interleave(lambda: self.write(", "), self.traverse, typeparams)
1098+
self.interleave(lambda: self.write(", "), self.traverse, type_params)
10991099

11001100
def visit_TypeVar(self, node):
11011101
self.write(node.name)
@@ -1112,7 +1112,7 @@ def visit_ParamSpec(self, node):
11121112
def visit_TypeAlias(self, node):
11131113
self.fill("type ")
11141114
self.traverse(node.name)
1115-
self._typeparams_helper(node.typeparams)
1115+
self._type_params_helper(node.type_params)
11161116
self.write(" = ")
11171117
self.traverse(node.value)
11181118

Misc/NEWS.d/next/Core and Builtins/2023-04-25-08-43-11.gh-issue-103763.ZLBZk1.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ attribute. This is implemented as a new AST node ``ast.TypeAlias``.
88

99
New syntax (``class X[T]: ...``, ``def func[T](): ...``) is added for defining
1010
generic functions and classes. This is implemented as a new
11-
``typeparams`` attribute on the AST nodes for classes and functions.
11+
``type_params`` attribute on the AST nodes for classes and functions.
1212
This node holds instances of the new AST classes ``ast.TypeVar``,
1313
``ast.ParamSpec``, and ``ast.TypeVarTuple``.
1414

Parser/Python.asdl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ module Python
88
| Expression(expr body)
99
| FunctionType(expr* argtypes, expr returns)
1010

11-
stmt = FunctionDef(identifier name, typeparam* typeparams, arguments args,
11+
stmt = FunctionDef(identifier name, type_param* type_params, arguments args,
1212
stmt* body, expr* decorator_list, expr? returns,
1313
string? type_comment)
14-
| AsyncFunctionDef(identifier name, typeparam* typeparams, arguments args,
14+
| AsyncFunctionDef(identifier name, type_param* type_params, arguments args,
1515
stmt* body, expr* decorator_list, expr? returns,
1616
string? type_comment)
1717

1818
| ClassDef(identifier name,
19-
typeparam* typeparams,
19+
type_param* type_params,
2020
expr* bases,
2121
keyword* keywords,
2222
stmt* body,
@@ -25,7 +25,7 @@ module Python
2525

2626
| Delete(expr* targets)
2727
| Assign(expr* targets, expr value, string? type_comment)
28-
| TypeAlias(expr name, typeparam* typeparams, expr value)
28+
| TypeAlias(expr name, type_param* type_params, expr value)
2929
| AugAssign(expr target, operator op, expr value)
3030
-- 'simple' indicates that we annotate simple name without parens
3131
| AnnAssign(expr target, expr annotation, expr? value, int simple)
@@ -145,8 +145,8 @@ module Python
145145

146146
type_ignore = TypeIgnore(int lineno, string tag)
147147

148-
typeparam = TypeVar(identifier name, expr? bound)
149-
| ParamSpec(identifier name)
150-
| TypeVarTuple(identifier name)
151-
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
148+
type_param = TypeVar(identifier name, expr? bound)
149+
| ParamSpec(identifier name)
150+
| TypeVarTuple(identifier name)
151+
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
152152
}

Parser/action_helpers.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ _PyPegen_function_def_decorators(Parser *p, asdl_expr_seq *decorators, stmt_ty f
752752
assert(function_def != NULL);
753753
if (function_def->kind == AsyncFunctionDef_kind) {
754754
return _PyAST_AsyncFunctionDef(
755-
function_def->v.FunctionDef.name, function_def->v.FunctionDef.typeparams,
755+
function_def->v.FunctionDef.name, function_def->v.FunctionDef.type_params,
756756
function_def->v.FunctionDef.args,
757757
function_def->v.FunctionDef.body, decorators, function_def->v.FunctionDef.returns,
758758
function_def->v.FunctionDef.type_comment, function_def->lineno,
@@ -761,7 +761,7 @@ _PyPegen_function_def_decorators(Parser *p, asdl_expr_seq *decorators, stmt_ty f
761761
}
762762

763763
return _PyAST_FunctionDef(
764-
function_def->v.FunctionDef.name, function_def->v.FunctionDef.typeparams,
764+
function_def->v.FunctionDef.name, function_def->v.FunctionDef.type_params,
765765
function_def->v.FunctionDef.args,
766766
function_def->v.FunctionDef.body, decorators,
767767
function_def->v.FunctionDef.returns,
@@ -776,7 +776,7 @@ _PyPegen_class_def_decorators(Parser *p, asdl_expr_seq *decorators, stmt_ty clas
776776
{
777777
assert(class_def != NULL);
778778
return _PyAST_ClassDef(
779-
class_def->v.ClassDef.name, class_def->v.ClassDef.typeparams,
779+
class_def->v.ClassDef.name, class_def->v.ClassDef.type_params,
780780
class_def->v.ClassDef.bases, class_def->v.ClassDef.keywords,
781781
class_def->v.ClassDef.body, decorators,
782782
class_def->lineno, class_def->col_offset, class_def->end_lineno,

0 commit comments

Comments
 (0)