Skip to content
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

Support typing.Protocol #135

Open
liran-funaro opened this issue Mar 13, 2019 · 2 comments
Open

Support typing.Protocol #135

liran-funaro opened this issue Mar 13, 2019 · 2 comments

Comments

@liran-funaro
Copy link

liran-funaro commented Mar 13, 2019

PEP-0544 introduce typing.Protocol which allows defining an interface that can be validated on runtime.
This is currently available via a non-official extension to the typing module called typing-extensions.

Although it seems similar to zope functionality, it is very different:

  1. It does not verify the arguments of the methods. Not that the implementation has the correct number of arguments and not the arguments' typing.
  2. Their implementation meant for static type checking.

Can zope utilize the already existing validation implementation to also validate Protocols on runtime.
This will allow a developer to write an interface once (via a Protocol) that could be checked statically using the existing Protocol implementation and also dynamically using zope's implementation.

See more information on this StackOverflow thread: https://stackoverflow.com/questions/43830996/verify-that-an-unknown-module-object-is-obliged-to-a-specific-interface-python/55131689

@pauleveritt
Copy link

I'm not sure how I feel about protocols where the implementers don't have to say what interfaces they support. It matches duck typing, but it is hard for tools that want to go find implementations (IDEs, a registry, etc.)

Still, in some mythical future zope.interface, sitting atop that machinery would indeed give (2) above, which is a big win for those buying into mypy or PyCharm.

@pauleveritt
Copy link

That said, PEP 544 (under rejected ideas) does say interfaces are conceptually a superset of protocols. So your point stands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants