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

convert a protocol to an interface #45

Open
graingert opened this issue Apr 1, 2021 · 3 comments
Open

convert a protocol to an interface #45

graingert opened this issue Apr 1, 2021 · 3 comments

Comments

@graingert
Copy link
Contributor

it should be possible to create a zope.interface.Interface by introspecting a typing.Protocol

class SomeProtocol(typing.Protocol):
    @property
    def foo(self) -> str: ...

    def ham(self) -> int: ...

ISome = mypy_zope.fromProtocol("ISome", SomeProtocol)
@graingert
Copy link
Contributor Author

this would also allow me to define self-types: #44

@kedder
Copy link
Member

kedder commented Apr 2, 2021

I'm not a big fan of having mypy_zope to be executed at runtime. It is a static analyzer and ideally shouldn't be a runtime dependency. And Protocols are kind of alternative to zope interfaces, so I suspect they will not play well together.

@glyph
Copy link

glyph commented Sep 16, 2022

This is probably something that should land in zope.interface itself for the runtime component, but mypy-zope would need to be aware of it.

As far as protocols and interfaces playing nicely together, I think it should work fine; they're mostly different spellings of the same thing.

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

3 participants