Add types module for explicit provider typing

This commit is contained in:
Roman Mogylatov 2020-08-26 21:18:03 -04:00
parent d600c6cde4
commit a2fb095e69
3 changed files with 18 additions and 2 deletions

View File

@ -14,6 +14,9 @@ from typing import (
Coroutine as _Coroutine,
)
from .types import Provider as _Provider
Injection = Any
T = TypeVar('T')
@ -24,7 +27,7 @@ class OverridingContext:
def __exit__(self, *_: Any) -> None: ...
class Provider:
class Provider(_Provider):
def __init__(self) -> None: ...
def __call__(self, *args: Injection, **kwargs: Injection) -> Any: ...
def __deepcopy__(self, memo: Optional[Dict[str, Any]]) -> Provider: ...

View File

@ -0,0 +1,9 @@
from typing import TypeVar, Generic, Any
Injection = Any
T = TypeVar('T')
class Provider(Generic[T]):
def __call__(self, *args: Injection, **kwargs: Injection) -> T: ...

View File

@ -1,6 +1,6 @@
from typing import Tuple, Any, Dict
from dependency_injector import providers
from dependency_injector import providers, types
class Animal:
@ -62,3 +62,7 @@ provider9 = providers.FactoryAggregate(
factory_a_9: providers.Factory = provider9.a
factory_b_9: providers.Factory = provider9.b
val9: Any = provider9('a')
# Test 10: to check the explicit typing
factory10: types.Provider[Animal] = providers.Factory(Cat)
animal10: Animal = factory10()