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

mypy stubs #48

Open
hasii2011 opened this issue Mar 28, 2022 · 1 comment
Open

mypy stubs #48

hasii2011 opened this issue Mar 28, 2022 · 1 comment

Comments

@hasii2011
Copy link

Do you have the above somewhere?

@Diogo-Rossi
Copy link

I'm also looking for stubs to this lib, but for pyright (which is used inside pylance).

I'm not very familiar with stubs rules, but I wrote a little __init__.pyi to solve my problem for now, shown below.

But it does not cover the case of multiple interfaces implementation.

For this particular case, I have to manually create the output of implements
and then create the implementation by multiple inheritance:

class I1(Interface):
    def method1(self, x):
        pass

class I2(Interface):
    def method2(self, y):
        pass

iI1, iI2 = implements(I1), implements(I2)

class ImplBoth(iI1,iI2):
    ...

For the other cases, this stub is working, so far.

__init__.pyi

from .default import default as default
from .interface import (implements as implements,
                        Interface as Interface,
                        InvalidImplementation as InvalidImplementation)

__all__ = [
    "default",
    "InvalidImplementation",
    "Interface",
    "implements",
]

from typing import TypeVar

InterfaceType = TypeVar("InterfaceType")
DefaultMethod = TypeVar("DefaultMethod")

class Interface: ...
    
def implements(interface: InterfaceType) -> InterfaceType: ...

def default(method: DefaultMethod) -> DefaultMethod:
    """Default implementation of a function in terms of interface methods."""
    ...

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