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

some way to define self types #44

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

some way to define self types #44

graingert opened this issue Apr 1, 2021 · 2 comments

Comments

@graingert
Copy link
Contributor

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"

@graingert
Copy link
Contributor Author

graingert commented Apr 1, 2021

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

@kedder
Copy link
Member

kedder commented Apr 2, 2021

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.

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

2 participants