8000 gh-123881: make compiler add the .generic_base base class without constructing AST nodes by iritkatriel · Pull Request #123883 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-123881: make compiler add the .generic_base base class without constructing AST nodes #123883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add action helper for ClassDef
  • Loading branch information
iritkatriel committed Sep 9, 2024
commit 031c6972cdb9e7328c83115bf7e2e81cc2921ba1
5 changes: 1 addition & 4 deletions Grammar/python.gram
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,7 @@ 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,
(b) ? ((expr_ty) b)->v.Call.args : NULL,
(b) ? ((expr_ty) b)->v.Call.keywords : NULL,
c, NULL, t, EXTRA) }
_PyPegen_class_def(a, b, c, t, EXTRA) }

# Function definitions
# --------------------
Expand Down
16 changes: 16 additions & 0 deletions Parser/action_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,22 @@ _PyPegen_function_def_decorators(Parser *p, asdl_expr_seq *decorators, stmt_ty f
function_def->end_lineno, function_def->end_col_offset, p->arena);
}

/* Construct a ClassDef */
stmt_ty
_PyPegen_class_def(expr_ty a, arguments_ty b, asdl_stmt_seq *c, asdl_type_param_seq *t,
int lineno, int col_offset, int end_lineno, int end_col_offset,
PyArena *arena)
{
identifier name = a->v.Name.id;
asdl_expr_seq *bases = (b) ? ((expr_ty) b)->v.Call.args : NULL;
asdl_keyword_seq *keywords = (b) ? ((expr_ty) b)->v.Call.keywords : NULL;
asdl_stmt_seq *body = c;
asdl_expr_seq *decorator_list = NULL;
asdl_type_param_seq *type_params = t;
return _PyAST_ClassDef(name, bases, keywords, body, decorator_list, type_params,
lineno, col_offset, end_lineno, end_col_offset, arena);
}

/* Construct a ClassDef equivalent to class_def, but with decorators */
stmt_ty
_PyPegen_class_def_decorators(Parser *p, asdl_expr_seq *decorators, stmt_ty class_def)
Expand Down
2 changes: 1 addition & 1 deletion Parser/parser.c

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

2 changes: 2 additions & 0 deletions Parser/pegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ expr_ty _PyPegen_formatted_value(Parser *, expr_ty, Token *, ResultTokenWithMeta
int, int, int, int, PyArena *);
AugOperator *_PyPegen_augoperator(Parser*, operator_ty type);
stmt_ty _PyPegen_function_def_decorators(Parser *, asdl_expr_seq *, stmt_ty);
stmt_ty _PyPegen_class_def(expr_ty, arguments_ty, asdl_stmt_seq *,
asdl_type_param_seq *, int, int, int, int, PyArena *);
stmt_ty _PyPegen_class_def_decorators(Parser *, asdl_expr_seq *, stmt_ty);
KeywordOrStarred *_PyPegen_keyword_or_starred(Parser *, void *, int);
asdl_expr_seq *_PyPegen_seq_extract_starred_exprs(Parser *, asdl_seq *);
Expand Down
0