diff --git a/pep-0696.rst b/pep-0696.rst index 564449904d9..1759b7fee5b 100644 --- a/pep-0696.rst +++ b/pep-0696.rst @@ -2,13 +2,15 @@ PEP: 696 Title: Type defaults for TypeVarLikes Author: James Hilton-Balfe Sponsor: Jelle Zijlstra -Discussions-To: typing-sig@python.org +Discussions-To: https://mail.python.org/archives/list/typing-sig@python.org/thread/7VWBZWXTCX6RAJO6GG67BAXUPFZ24NTC Status: Draft Type: Standards Track Topic: Typing Content-Type: text/x-rst Created: 14-Jul-2022 Python-Version: 3.12 +Post-History: `22-Mar-2022 `__, + `08-Jan-2023 `__, Abstract -------- @@ -143,7 +145,7 @@ future, this might be possible (see `Interaction with PEP '''''''''''''''''''''' ``ParamSpec`` defaults are defined using the same syntax as -``TypeVar`` \ s but use a ``list`` or ``tuple`` of types or an ellipsis +``TypeVar`` \ s but use a ``list`` of types or an ellipsis literal "``...``" or another in-scope ``ParamSpec`` (see :ref:`696-scoping-rules`). .. code-block:: py @@ -152,9 +154,9 @@ literal "``...``" or another in-scope ``ParamSpec`` (see :ref:`696-scoping-rules class Foo(Generic[DefaultP]): ... - reveal_type(Foo) # type is type[Foo[DefaultP = (str, int)]] - reveal_type(Foo()) # type is Foo[(str, int)] - reveal_type(Foo[(bool, bool)]()) # type is Foo[(bool, bool)] + reveal_type(Foo) # type is type[Foo[DefaultP = [str, int]]] + reveal_type(Foo()) # type is Foo[[str, int]] + reveal_type(Foo[[bool, bool]]()) # type is Foo[[bool, bool]] ``TypeVarTuple`` Defaults ''''''''''''''''''''''''' @@ -399,6 +401,9 @@ The following changes would be required to both ``GenericAlias``\ es: - ideally, logic to determine if subscription (like ``Generic[T, DefaultT]``) would be valid. +A reference implementation of the runtime changes can be found at +https://github.com/Gobot1234/cpython/tree/pep-696 + A reference implementation of the type checker can be found at https://github.com/Gobot1234/mypy/tree/TypeVar-defaults @@ -418,14 +423,14 @@ using the "=" operator inside of the square brackets like so: class Foo[T = str]: ... # ParamSpecs - class Baz[**P = (int, str)]: ... + class Baz[**P = [int, str]]: ... # TypeVarTuples class Qux[*Ts = *tuple[int, bool]]: ... # TypeAliases type Foo[T, U = str] = Bar[T, U] - type Baz[**P = (int, str)] = Spam[**P] + type Baz[**P = [int, str]] = Spam[**P] type Qux[*Ts = *tuple[str]] = Ham[*Ts] type Rab[U, T = str] = Bar[T, U]