diff options
author | Jelle Zijlstra <jelle.zijlstra@gmail.com> | 2024-05-03 06:17:32 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-03 06:17:32 -0700 |
commit | ca269e58c290be8ca11bb728004ea842d9f85e3a (patch) | |
tree | 7af6ddffd5195536343780ef7aeb338ef460501e /Grammar | |
parent | 852263e1086748492602a90347ecc0a3925e1dda (diff) | |
download | cpython-ca269e58c290be8ca11bb728004ea842d9f85e3a.tar.gz cpython-ca269e58c290be8ca11bb728004ea842d9f85e3a.zip |
gh-116126: Implement PEP 696 (#116129)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Diffstat (limited to 'Grammar')
-rw-r--r-- | Grammar/python.gram | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/Grammar/python.gram b/Grammar/python.gram index 05d7837e3aa..1c1c53c4b73 100644 --- a/Grammar/python.gram +++ b/Grammar/python.gram @@ -647,21 +647,25 @@ type_params[asdl_type_param_seq*]: '[' t=type_param_seq ']' { type_param_seq[asdl_type_param_seq*]: a[asdl_type_param_seq*]=','.type_param+ [','] { a } type_param[type_param_ty] (memo): - | a=NAME b=[type_param_bound] { _PyAST_TypeVar(a->v.Name.id, b, EXTRA) } + | a=NAME b=[type_param_bound] c=[type_param_default] { _PyAST_TypeVar(a->v.Name.id, b, c, EXTRA) } | '*' a=NAME colon=':' e=expression { RAISE_SYNTAX_ERROR_STARTING_FROM(colon, e->kind == Tuple_kind ? "cannot use constraints with TypeVarTuple" : "cannot use bound with TypeVarTuple") } - | '*' a=NAME { _PyAST_TypeVarTuple(a->v.Name.id, EXTRA) } + | '*' a=NAME b=[type_param_starred_default] { _PyAST_TypeVarTuple(a->v.Name.id, b, EXTRA) } | '**' a=NAME colon=':' e=expression { RAISE_SYNTAX_ERROR_STARTING_FROM(colon, e->kind == Tuple_kind ? "cannot use constraints with ParamSpec" : "cannot use bound with ParamSpec") } - | '**' a=NAME { _PyAST_ParamSpec(a->v.Name.id, EXTRA) } + | '**' a=NAME b=[type_param_default] { _PyAST_ParamSpec(a->v.Name.id, b, EXTRA) } type_param_bound[expr_ty]: ':' e=expression { e } +type_param_default[expr_ty]: '=' e=expression { + CHECK_VERSION(expr_ty, 13, "Type parameter defaults are", e) } +type_param_starred_default[expr_ty]: '=' e=star_expression { + CHECK_VERSION(expr_ty, 13, "Type parameter defaults are", e) } # EXPRESSIONS # ----------- |