Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions pep-0696.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ PEP: 696
Title: Type defaults for TypeVarLikes
Author: James Hilton-Balfe <[email protected]>
Sponsor: Jelle Zijlstra <[email protected]>
Discussions-To: [email protected]
Discussions-To: https://mail.python.org/archives/list/[email protected]/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/[email protected]/thread/7VWBZWXTCX6RAJO6GG67BAXUPFZ24NTC/>`__,
`08-Jan-2023 <https://discuss.python.org/t/pep-696-type-defaults-for-typevarlikes/22569/5/>`__,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason the linter (correctly) flagged this was due to it accidentally being a direct link to an arbitrary post down in the thread, instead of the thread itself. You were able to unintentionally bypass it due to the escape hatch of manually adding a trailing slash (which is not added by Discourse by default, like the post number is) recently implemented in #3005 in response to an author request in #3004 , which allows direct links to specific posts in special cases where the author specifically finds it necessary and intends to do so.

To actually fix this properly, the trailing post number, 5/, should be removed from this URL so it goes to the thread, not an arbitrary post within it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've opened #3053 to fix this.


Abstract
--------
Expand Down Expand Up @@ -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
Expand All @@ -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
'''''''''''''''''''''''''
Expand Down Expand Up @@ -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

Expand All @@ -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]

Expand Down