8000 Use Name expr for TypeAlias · python/cpython@f7c513d · GitHub
[go: up one dir, main page]

Skip to content

Commit f7c513d

Browse files
committed
Use Name expr for TypeAlias
1 parent 830b36a commit f7c513d

File tree

8 files changed

+21
-16
lines changed

8 files changed

+21
-16
lines changed

Grammar/python.gram

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,8 @@ keyword_pattern[KeyPatternPair*]:
634634

635635
type_alias[stmt_ty]:
636636
| "type" n=NAME t=[type_params] '=' b=expression {
637-
CHECK_VERSION(stmt_ty, 12, "Type statement is", _PyAST_TypeAlias(n->v.Name.id, t, b, EXTRA)) }
637+
CHECK_VERSION(stmt_ty, 12, "Type statement is",
638+
_PyAST_TypeAlias(CHECK(expr_ty, _PyPegen_set_expr_context(p, n, Store)), t, b, EXTRA)) }
638639

639640
# Type parameter declaration
640641
# --------------------------

Include/internal/pycore_ast.h

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

Lib/ast.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,8 @@ def visit_ParamSpec(self, node):
10701070
self.write("**" + node.name)
10711071

10721072
def visit_TypeAlias(self, node):
1073-
self.fill(&qu 8000 ot;type " + node.name)
1073+
self.fill("type ")
1074+
self.traverse(node.name)
10741075
self._typeparams_helper(node.typeparams)
10751076
self.write(" = ")
10761077
self.traverse(node.value)

Parser/Python.asdl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module Python
2525

2626
| Delete(expr* targets)
2727
| Assign(expr* targets, expr value, string? type_comment)
28-
| TypeAlias(identifier name, typeparam* typeparams, expr value)
28+
| TypeAlias(expr name, typeparam* typeparams, 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)

Parser/parser.c

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/Python-ast.c

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

Python/ast.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,8 @@ validate_stmt(struct validator *state, stmt_ty stmt)
747747
validate_expr(state, stmt->v.AnnAssign.annotation, Load);
748748
break;
749749
case TypeAlias_kind:
750-
ret = validate_expr(state, stmt->v.TypeAlias.value, Load);
750+
ret = validate_name(stmt->v.TypeAlias.name->v.Name.id) &&
751+
validate_expr(state, stmt->v.TypeAlias.value, Load);
751752
break;
752753
case For_kind:
753754
ret = validate_expr(state, stmt->v.For.target, Store) &&

Python/ast_opt.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,8 @@ astfold_stmt(stmt_ty node_, PyArena *ctx_, _PyASTOptimizeState *state)
924924
CALL_OPT(astfold_expr, expr_ty, node_->v.AnnAssign.value);
925925
break;
926926
case TypeAlias_kind:
927+
CALL(astfold_expr, expr_ty, node_->v.TypeAlias.name);
928+
CALL_SEQ(astfold_stmt, typeparam, node_->v.TypeAlias.typeparams);
927929
CALL(astfold_expr, expr_ty, node_->v.TypeAlias.value);
928930
break;
929931
case For_kind:

0 commit comments

Comments
 (0)
0