Skip to content

Commit 3fd5a77

Browse files
committed
Parser and runtime support for PEP 696
1 parent f4ea500 commit 3fd5a77

File tree

13 files changed

+889
-544
lines changed

13 files changed

+889
-544
lines changed

Grammar/python.gram

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -646,21 +646,22 @@ type_params[asdl_typeparam_seq*]: '[' t=type_param_seq ']' {
646646
type_param_seq[asdl_typeparam_seq*]: a[asdl_typeparam_seq*]=','.type_param+ [','] { a }
647647

648648
type_param[typeparam_ty] (memo):
649-
| a=NAME b=[type_param_bound] { _PyAST_TypeVar(a->v.Name.id, b, EXTRA) }
649+
| a=NAME b=[type_param_bound] c=[type_param_default] { _PyAST_TypeVar(a->v.Name.id, b, c, EXTRA) }
650650
| '*' a=NAME colon=":" e=expression {
651651
RAISE_SYNTAX_ERROR_STARTING_FROM(colon, e->kind == Tuple_kind
652652
? "cannot use constraints with TypeVarTuple"
653653
: "cannot use bound with TypeVarTuple")
654654
}
655-
| '*' a=NAME { _PyAST_TypeVarTuple(a->v.Name.id, EXTRA) }
655+
| '*' a=NAME b=[type_param_default] { _PyAST_TypeVarTuple(a->v.Name.id, b, EXTRA) }
656656
| '**' a=NAME colon=":" e=expression {
657657
RAISE_SYNTAX_ERROR_STARTING_FROM(colon, e->kind == Tuple_kind
658658
? "cannot use constraints with ParamSpec"
659659
: "cannot use bound with ParamSpec")
660660
}
661-
| '**' a=NAME { _PyAST_ParamSpec(a->v.Name.id, EXTRA) }
661+
| '**' a=NAME b=[type_param_default] { _PyAST_ParamSpec(a->v.Name.id, b, EXTRA) }
662662

663663
type_param_bound[expr_ty]: ":" e=expression { e }
664+
type_param_default[expr_ty]: "=" e=expression { e }
664665

665666
# EXPRESSIONS
666667
# -----------

Include/internal/pycore_ast.h

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

Include/internal/pycore_ast_state.h

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

Include/internal/pycore_intrinsics.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
#define INTRINSIC_TYPEVAR_WITH_BOUND 3
2424
#define INTRINSIC_TYPEVAR_WITH_CONSTRAINTS 4
2525
#define INTRINSIC_SET_FUNCTION_TYPE_PARAMS 5
26+
#define INTRINSIC_SET_TYPEPARAM_DEFAULT 6
2627

27-
#define MAX_INTRINSIC_2 5
28+
#define MAX_INTRINSIC_2 6
2829

2930

3031
typedef PyObject *(*instrinsic_func1)(PyThreadState* tstate, PyObject *value);

Include/internal/pycore_typevarobject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ extern PyObject *_Py_make_paramspec(PyThreadState *, PyObject *);
1313
extern PyObject *_Py_make_typevartuple(PyThreadState *, PyObject *);
1414
extern PyObject *_Py_make_typealias(PyThreadState *, PyObject *);
1515
extern PyObject *_Py_subscript_generic(PyThreadState *, PyObject *);
16+
extern PyObject *_Py_set_typeparam_default(PyThreadState *, PyObject *, PyObject *);
1617
extern int _Py_initialize_generic(PyInterpreterState *);
1718
extern void _Py_clear_generic_types(PyInterpreterState *);
1819

Objects/clinic/typevarobject.c.h

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

0 commit comments

Comments
 (0)