mypy-zope icon indicating copy to clipboard operation
mypy-zope copied to clipboard

convert a protocol to an interface

Open graingert opened this issue 4 years ago • 3 comments

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 avatar Apr 01 '21 23:04 graingert

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

graingert avatar Apr 01 '21 23:04 graingert

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.

kedder avatar Apr 02 '21 19:04 kedder

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.

glyph avatar Sep 16 '22 00:09 glyph