-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
bpo-43224: Implement PEP 646 changes to typing.py #31021
Conversation
Co-authored-by: Jelle Zijlstra <[email protected]>
Co-authored-by: Jelle Zijlstra <[email protected]>
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.
(Reviewed three-fourths of it and got tired after a couple of hours. Will review the rest after the changes.)
Overall, I think we'd want to try other things beyond Unpack[Ts]
: Unpack[tuple[int, ...]]
, Unpack[tuple[int, str]]
, and Unpack[tuple[int, Unpack[Ts], str]]
. I've tried to point to cases inline.
I'd assumed all these comments had been posted weeks ago - I'd missed the part where you actually have to click the 'Submit code review' button to post them! Uff.
Ah, that clears up a mystery :) I was wondering why many comments were unaddressed.
Do we need to validate *args: <foo>
somewhere? For example, *args: Ts
vs *args: Unpack[Ts]
.
What if someone tries Union[*Ts]
or Union[Ts]
? Same for other special forms that call _type_check
:
ClassVar
Optional
Final
(i.e.,x: Final[Ts]
)TypeGuard
- What about
Concatenate[Ts, P]
andConcatenate[*Ts, P]
?
n00b question: how do I run the Python tests in my local clone of this repository? Wanted to experiment.
First compile Python, as explained in "Quick reference" at https://devguide.python.org/. To run just the typing tests, the easiest way is just |
Thanks, Jelle. Should have RTFM'ed but was being lazy :| @mrahtz Some tests fail locally (and on CI, apparently). |
Co-authored-by: Jelle Zijlstra <[email protected]>
@gvanrossum @JelleZijlstra @pradeep90 There's a high-level design point I've just realised we should discuss. In the PEP itself, we stated that (@gvanrossum, in case you haven't followed the chain of comments on the PR so far, there were two main reasons to try doing it this way: 1. It means we can avoid the need for a middleman classes This raises two questions:
|
Thanks for bringing this up! Here are my takes:
|
Exactly what Jelle says. |
…ds compatibility now
@JelleZijlstra @gvanrossum Thanks for confirming re |
(Fixed a merge conflict) |
On the subject of what to do about type substitution, Pradeep had the excellent idea of moving discussion to a future PR, given how long even this PR has taken. For now I've excised all the extra logic required, instead raising For what it's worth, though, given that both Pradeep and Jelle lean towards thinking simple is better, for the follow-up PR, I'll try drafting a prototype of Jelle's suggestion: having the subscription operator just return a new GenericAlias. |
P.S. bedevere-bot: I have made the requested changes; please review again. |
Thanks for making the requested changes! @JelleZijlstra: please review the changes made to this pull request. |
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.
Let's do it.
I'm planning to merge this PR once 3.11.0a6 is out (cc @gvanrossum @Fidget-Spinner).
Congratulations! |
Thanks @mrahtz for the code, and thanks @JelleZijlstra for the review. Thanks @pradeep90 for your help. This is a monumental change! |
Fantastic! Thank you @JelleZijlstra and @pradeep90 for the review, and @gvanrossum for your continuing support :) |
These are the parts of the old PR (#30398) relevant to
typing.py
.Note that we haven't yet merged the grammar PR (#31018), so for the time being all the tests just use
Unpack
. We can add tests using the actual star operator in a future PR.https://bugs.python.org/issue43224