-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
bpo-37058: PEP 544: Add Protocol to typing module #13585
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
Conversation
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 didn't really review the code, I trust it's just a copy of what's in the external typing.py or typing_extensions.py.
|
||
func(C()) # Passes static type check | ||
|
||
See :pep:`544` for details. Protocol classes decorated with |
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 is okay for now, but at some point we may want to make it so that the docs are self-contained without any references to PEPs. (This is so that in the future the implementation can evolve, and the docs should describe the current implementation, while the PEP describes the implementation as it was at the time the PEP was finalized.)
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.
Yes, we can expand the docs later.
To be precise it is not literally a copy. I added some docstrings, few more comments, and factored-out couple pieces of code into private helpers. The tests however are 1:1 copied, so there are no semantic changes. |
@gvanrossum Thanks for review! (Also thank you for reviewing the other PEP PRs!) |
I tried to get rid of the `_ProtocolMeta`, but unfortunately it didn'y work. My idea to return a generic alias from `@runtime_checkable` made runtime protocols unpickleable. I am not sure what is worse (a custom metaclass or having some classes unpickleable), so I decided to stick with the status quo (since there were no complains so far). So essentially this is a copy of the implementation in `typing_extensions` with two modifications: * Rename `@runtime` to `@runtime_checkable` (plus corresponding updates). * Allow protocols that extend `collections.abc.Iterable` etc.
cc @ambv @JukkaL
I tried to get rid of the
_ProtocolMeta
, but unfortunately it didn'y work. My idea to return a generic alias from@runtime_checkable
made runtime protocols unpickleable. I am not sure what is worse (a custom metaclass or having some classes unpickleable), so I decided to stick with the status quo (since there were no complains so far). So essentially this is a copy of the implementation intyping_extensions
with two modifications:@runtime
to@runtime_checkable
(plus corresponding updates).collections.abc.Iterable
etc.https://bugs.python.org/issue37058