Repository navigation
PEP 696: Final round of changes before submitting to SC #3052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
506636c
Remove support for tuples as ParamSpec defaults
Gobot1234 08a5ed4
Update discussions to and post history
Gobot1234 0db657f
Add link to reference cpython impl
Gobot1234 c3befd9
Try fixing lint
Gobot1234 d334dd3
Try fixing the lint for the second time
Gobot1234 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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/>`__, | ||
|
|
||
| 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] | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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.