mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-07-09 06:43:13 +03:00
Add stub for Dependency provider
This commit is contained in:
parent
821f0be3b7
commit
df9036b0dc
|
@ -42,6 +42,15 @@ class Delegate(Provider):
|
||||||
def __call__(self, *args: Injection, **kwargs: Injection) -> 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]):
|
class Callable(Provider, Generic[T]):
|
||||||
def __init__(self, provides: _Callable[..., T], *args: Injection, **kwargs: Injection) -> None: ...
|
def __init__(self, provides: _Callable[..., T], *args: Injection, **kwargs: Injection) -> None: ...
|
||||||
def __call__(self, *args: Injection, **kwargs: Injection) -> T: ...
|
def __call__(self, *args: Injection, **kwargs: Injection) -> T: ...
|
||||||
|
|
22
tests/typing/dependency.py
Normal file
22
tests/typing/dependency.py
Normal 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
|
|
@ -4,7 +4,6 @@ from dependency_injector import providers
|
||||||
|
|
||||||
|
|
||||||
class Animal:
|
class Animal:
|
||||||
xyz: int = 123
|
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user