mypy-zope
mypy-zope copied to clipboard
convert a protocol to an interface
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)
this would also allow me to define self-types: https://github.com/Shoobx/mypy-zope/issues/44
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.
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.