Skip to content

Commit

Permalink
pythongh-104799: Move location of type_params AST fields (python#104828)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
  • Loading branch information
JelleZijlstra and AlexWaygood committed May 26, 2023
1 parent 6e1eccd commit ba73473
Show file tree
Hide file tree
Showing 9 changed files with 297 additions and 266 deletions.
12 changes: 6 additions & 6 deletions Doc/library/ast.rst
Expand Up @@ -1724,7 +1724,6 @@ Function and class definitions
body=[
FunctionDef(
name='f',
type_params=[],
args=arguments(
posonlyargs=[],
args=[
Expand All @@ -1749,7 +1748,8 @@ Function and class definitions
decorator_list=[
Name(id='decorator1', ctx=Load()),
Name(id='decorator2', ctx=Load())],
returns=Constant(value='return annotation'))],
returns=Constant(value='return annotation'),
type_params=[])],
type_ignores=[])


Expand Down Expand Up @@ -1848,7 +1848,6 @@ Function and class definitions
body=[
ClassDef(
name='Foo',
type_params=[],
bases=[
Name(id='base1', ctx=Load()),
Name(id='base2', ctx=Load())],
Expand All @@ -1860,7 +1859,8 @@ Function and class definitions
Pass()],
decorator_list=[
Name(id='decorator1', ctx=Load()),
Name(id='decorator2', ctx=Load())])],
Name(id='decorator2', ctx=Load())],
type_params=[])],
type_ignores=[])

Async and await
Expand All @@ -1887,7 +1887,6 @@ Async and await
body=[
AsyncFunctionDef(
name='f',
type_params=[],
args=arguments(
posonlyargs=[],
args=[],
Expand All @@ -1901,7 +1900,8 @@ Async and await
func=Name(id='other_func', ctx=Load()),
args=[],
keywords=[])))],
decorator_list=[])],
decorator_list=[],
type_params=[])],
type_ignores=[])


Expand Down
12 changes: 6 additions & 6 deletions Grammar/python.gram
Expand Up @@ -254,10 +254,10 @@ class_def[stmt_ty]:
class_def_raw[stmt_ty]:
| invalid_class_def_raw
| '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.keywords : NULL,
c, NULL, EXTRA) }
c, NULL, t, EXTRA) }

# Function definitions
# --------------------
Expand All @@ -269,17 +269,17 @@ function_def[stmt_ty]:
function_def_raw[stmt_ty]:
| invalid_def_raw
| '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)),
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 {
CHECK_VERSION(
stmt_ty,
5,
"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)),
b, NULL, a, NEW_TYPE_COMMENT(p, tc), EXTRA)
b, NULL, a, NEW_TYPE_COMMENT(p, tc), t, EXTRA)
) }

# Function parameters
Expand Down
36 changes: 18 additions & 18 deletions Include/internal/pycore_ast.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ba73473

Please sign in to comment.