diff --git a/MANIFEST.in b/MANIFEST.in index 69c8a787..b29eeb36 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,4 @@ -recursive-include src/dependency_injector *.py *.pyx *.pxd *.c +recursive-include src/dependency_injector *.py* *.c recursive-include tests *.py include README.rst include CONTRIBUTORS.rst @@ -6,3 +6,4 @@ include LICENSE.rst include requirements.txt include setup.py include tox.ini +include py.typed diff --git a/requirements-dev.txt b/requirements-dev.txt index c51f0e24..6947cf47 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -6,5 +6,6 @@ flake8 pydocstyle sphinx_autobuild pip +mypy -r requirements-ext.txt diff --git a/setup.py b/setup.py index 10e2653d..0f40a4b1 100644 --- a/setup.py +++ b/setup.py @@ -47,7 +47,7 @@ setup(name='dependency-injector', '': 'src', }, package_data={ - 'dependency_injector': ['*.pxd'], + 'dependency_injector': ['*.pxd', '*.pyi', 'py.typed'], }, ext_modules=[ Extension('dependency_injector.containers', diff --git a/src/dependency_injector/__init__.pyi b/src/dependency_injector/__init__.pyi new file mode 100644 index 00000000..e69de29b diff --git a/src/dependency_injector/providers.pyi b/src/dependency_injector/providers.pyi new file mode 100644 index 00000000..0b18179f --- /dev/null +++ b/src/dependency_injector/providers.pyi @@ -0,0 +1,10 @@ +from typing import TypeVar, Generic, Callable, Any + +Injection = Any +T = TypeVar('T') + + +class Factory(Generic[T]): + + def __init__(self, provides: Callable[..., T], *args: Injection, **kwargs: Injection) -> None: ... + def __call__(self, *args: Injection, **kwargs: Injection) -> T: ... diff --git a/src/dependency_injector/py.typed b/src/dependency_injector/py.typed new file mode 100644 index 00000000..e69de29b diff --git a/tests/typing/factory.py b/tests/typing/factory.py new file mode 100644 index 00000000..a13c79e7 --- /dev/null +++ b/tests/typing/factory.py @@ -0,0 +1,14 @@ +from dependency_injector import providers + + +class Animal: + ... + + +class Cat(Animal): + ... + + +provider = providers.Factory(Cat) + +animal: Animal = provider(1, 2, 3, b='1', c=2, e=0.0)