Add stub for Dependency provider

This commit is contained in:
Roman Mogylatov 2020-08-25 16:39:37 -04:00
parent 821f0be3b7
commit df9036b0dc
3 changed files with 31 additions and 1 deletions

View File

@ -42,6 +42,15 @@ class Delegate(Provider):
def __call__(self, *args: Injection, **kwargs: Injection) -> Provider: ...
class Dependency(Provider, Generic[T]):
def __init__(self, instance_of: Type[T]) -> None: ...
def __call__(self, *args: Injection, **kwargs: Injection) -> T: ...
@property
def provided(self) -> ProvidedInstance: ...
@property
def instance_of(self) -> Type[T]: ...
def provided_by(self, provider: Provider) -> OverridingContext: ...
class Callable(Provider, Generic[T]):
def __init__(self, provides: _Callable[..., T], *args: Injection, **kwargs: Injection) -> None: ...
def __call__(self, *args: Injection, **kwargs: Injection) -> T: ...

View File

@ -0,0 +1,22 @@
from typing import Type
from dependency_injector import providers
class Animal:
...
class Cat(Animal):
def __init__(self, *_, **__): ...
# Test 1: to check the return type
provider1 = providers.Dependency(instance_of=Animal)
provider1.override(providers.Factory(Cat))
var1: Animal = provider1()
# Test 2: to check the return type
provider2 = providers.Dependency(instance_of=Animal)
var2: Type[Animal] = provider2.instance_of

View File

@ -4,7 +4,6 @@ from dependency_injector import providers
class Animal:
xyz: int = 123
...