PEP 696: Final round of changes before submitting to SC (#3052)

This commit is contained in:
James Hilton-Balfe 2023-03-12 02:07:34 +00:00 committed by GitHub
parent 42c33bb982
commit e8b0cab081
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 7 deletions

View File

@ -2,13 +2,15 @@ PEP: 696
Title: Type defaults for TypeVarLikes
Author: James Hilton-Balfe <gobot1234yt@gmail.com>
Sponsor: Jelle Zijlstra <jelle.zijlstra@gmail.com>
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 <https://mail.python.org/archives/list/typing-sig@python.org/thread/7VWBZWXTCX6RAJO6GG67BAXUPFZ24NTC/>`__,
`08-Jan-2023 <https://discuss.python.org/t/pep-696-type-defaults-for-typevarlikes/22569/5/>`__,
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]