mypy-zope
mypy-zope copied to clipboard
some way to define self types
eg I might want to define
class ICopyable(zope.interface.Interface):
def copy(self: T) -> T:
pass
but I get "Interface methods should not have 'self' argument"
I can use this, but then I lose the type of the function in @implements
class ICopyable(zope.interface.Interface):
@zope.interface.interface.fromMethod
def copy(self: T) -> T:
pass
Right, interface method cannot have self argument - it won't work at runtime (my guess). However, we might make @zope.interface.interface.fromMethod trick work, if that's acceptable in your case. It feels a bit like a hack though. It isn't anywhere in the official docs.
The trick here is to make it work both at runtime and during static checking.