Skip to content

Commit ba73473

Browse files
gh-104799: Move location of type_params AST fields (#104828)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
1 parent 6e1eccd commit ba73473

File tree

9 files changed

+297
-266
lines changed

9 files changed

+297
-266
lines changed

Doc/library/ast.rst

+6-6
Original file line numberDiff line numberDiff line change
@@ -1724,7 +1724,6 @@ Function and class definitions
17241724
body=[
17251725
FunctionDef(
17261726
name='f',
1727-
type_params=[],
17281727
args=arguments(
17291728
posonlyargs=[],
17301729
args=[
@@ -1749,7 +1748,8 @@ Function and class definitions
17491748
decorator_list=[
17501749
Name(id='decorator1', ctx=Load()),
17511750
Name(id='decorator2', ctx=Load())],
1752-
returns=Constant(value='return annotation'))],
1751+
returns=Constant(value='return annotation'),
1752+
type_params=[])],
17531753
type_ignores=[])
17541754

17551755

@@ -1848,7 +1848,6 @@ Function and class definitions
18481848
body=[
18491849
ClassDef(
18501850
name='Foo',
1851-
type_params=[],
18521851
bases=[
18531852
Name(id='base1', ctx=Load()),
18541853
Name(id='base2', ctx=Load())],
@@ -1860,7 +1859,8 @@ Function and class definitions
18601859
Pass()],
18611860
decorator_list=[
18621861
Name(id='decorator1', ctx=Load()),
1863-
Name(id='decorator2', ctx=Load())])],
1862+
Name(id='decorator2', ctx=Load())],
1863+
type_params=[])],
18641864
type_ignores=[])
18651865

18661866
Async and await
@@ -1887,7 +1887,6 @@ Async and await
18871887
body=[
18881888
AsyncFunctionDef(
18891889
name='f',
1890-
type_params=[],
18911890
args=arguments(
18921891
posonlyargs=[],
18931892
args=[],
@@ -1901,7 +1900,8 @@ Async and await
19011900
func=Name(id='other_func', ctx=Load()),
19021901
args=[],
19031902
keywords=[])))],
1904-
decorator_list=[])],
1903+
decorator_list=[],
1904+
type_params=[])],
19051905
type_ignores=[])
19061906

19071907

Grammar/python.gram

+6-6
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,10 @@ class_def[stmt_ty]:
254254
class_def_raw[stmt_ty]:
255255
| invalid_class_def_raw
256256
| 'class' a=NAME t=[type_params] b=['(' z=[arguments] ')' { z }] ':' c=block {
257-
_PyAST_ClassDef(a->v.Name.id, t,
257+
_PyAST_ClassDef(a->v.Name.id,
258258
(b) ? ((expr_ty) b)->v.Call.args : NULL,
259259
(b) ? ((expr_ty) b)->v.Call.keywords : NULL,
260-
c, NULL, EXTRA) }
260+
c, NULL, t, EXTRA) }
261261

262262
# Function definitions
263263
# --------------------
@@ -269,17 +269,17 @@ function_def[stmt_ty]:
269269
function_def_raw[stmt_ty]:
270270
| invalid_def_raw
271271
| 'def' n=NAME t=[type_params] &&'(' params=[params] ')' a=['->' z=expression { z }] &&':' tc=[func_type_comment] b=block {
272-
_PyAST_FunctionDef(n->v.Name.id, t,
272+
_PyAST_FunctionDef(n->v.Name.id,
273273
(params) ? params : CHECK(arguments_ty, _PyPegen_empty_arguments(p)),
274-
b, NULL, a, NEW_TYPE_COMMENT(p, tc), EXTRA) }
274+
b, NULL, a, NEW_TYPE_COMMENT(p, tc), t, EXTRA) }
275275
| ASYNC 'def' n=NAME t=[type_params] &&'(' params=[params] ')' a=['->' z=expression { z }] &&':' tc=[func_type_comment] b=block {
276276
CHECK_VERSION(
277277
stmt_ty,
278278
5,
279279
"Async functions are",
280-
_PyAST_AsyncFunctionDef(n->v.Name.id, t,
280+
_PyAST_AsyncFunctionDef(n->v.Name.id,
281281
(params) ? params : CHECK(arguments_ty, _PyPegen_empty_arguments(p)),
282-
b, NULL, a, NEW_TYPE_COMMENT(p, tc), EXTRA)
282+
b, NULL, a, NEW_TYPE_COMMENT(p, tc), t, EXTRA)
283283
) }
284284

285285
# Function parameters

Include/internal/pycore_ast.h

+18-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)