Shoobx / mypy-zope

Plugin for mypy to support zope.interface
MIT License
39 stars 13 forks source link

convert a protocol to an interface #45

Open graingert opened 3 years ago

graingert commented 3 years ago

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 commented 3 years ago

this would also allow me to define self-types: https://github.com/Shoobx/mypy-zope/issues/44

kedder commented 3 years ago

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 commented 2 years ago

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.