-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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: Initial implementation of PEP 646 in typing.py #24527
Conversation
Hi! I only took a brief look (sorry I'll try to do a more thorough review if the PEP is accepted), but here's a possible general checklist of things you may have to do:
Please correct me if you think I missed anything. |
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.
This looks great. Thanks for working on this, Matthew!
Apart from the suggestions above from @Fidget-Spinner, could you also look at typing_extensions.py
? I saw a few uses of isinstance(..., TypeVar)
. Would be worth checking if they need updating.
Also, could you add tests for Tensor[()]
and Tensor
(without parameters)?
I'm catching up on old items. Is this ready to merge from your POV? |
Never mind, I didn't read this, I thought it was another PEP update. As an implementation update it will have to wait (but the proof-of-concept implementation is very much appreciated). |
Thanks for doing this. I don't think PEP 646 is accepted by the SC yet so no. Edit: woops messages posted at the same time and crossed |
Sorry, yes, should have said - just a proof of concept for now, posted here so it would get some initial feedback from the right people. |
This PR is stale because it has been open for 30 days with no activity. |
This PR is closed, but @Fidget-Spinner, I wanted to ask your advice on something. After a lot of churn on the PEP itself, I'm restarting work on the CPython implementation. I was going to tackle adding support to Thanks! |
@mrahtz Sorry, I've lost track of PEP 646 after its many revisions, so I'm not sure what the To clarify, if you want a base implementation for type checkers without the runtime stuff,
Y = type("Y", (), {})
y = Y()
y.__parameters__ = (1,)
>>> list[y].__parameters__
(1,)
PS. I would love to review the C and typing.py code for the implementation. While I'm useless at the grammar and parser, I'm somewhat better at the bytecode interpreter, builtin objects, and typing.py stuff. |
@mrahtz Could you explain what you mean by |
@pradeep90 Oops, sorry, I meant @Fidget-Spinner Ah, yeah, |
(Why are we discussing this in a closed PR? :-) Anyway, surely you meant Also, from the runtime's POV tuple is not special, and we need to assign a meaning to |
Currently this only supports the
Unpack[Ts]
form, but once the changes from PEP 637 are merged,*Ts
also works with no extra changes.I don't think this is finished yet - we need more tests, especially for aliases - but this is enough to begin discussion.
Notes:
_TypeVarLike
to_BoundVarianceMixin
, sinceTypeVarTuple
doesn't support bounds or variance yet, and it would be confusing ifTypeVarTuple
wasn't a_TypeVarLike
. I've created_TypeVarTypes
as a replacement._check_generic
to_check_type_parameter_count
to make its purpose clearer, and overhauled its body to supportTypeVarTuple
s._check_type_parameter_count
, I've removed the check on whethercls
is a generic a) so that the function only does one thing, and b) because I couldn't see any way for the function to be called on a class which wasn't generic (and none of the tests fail, so shrug).https://bugs.python.org/issue43224