Add stub for the List provider

This commit is contained in:
Roman Mogylatov 2020-08-26 17:48:44 -04:00
parent 3092b9d8f5
commit 5100f13bff
2 changed files with 43 additions and 0 deletions

View File

@ -7,6 +7,7 @@ from typing import (
Callable as _Callable,
Any,
Tuple,
List as _List,
Optional,
Dict,
Union,
@ -199,6 +200,7 @@ class FactoryAggregate(Provider):
class BaseSingleton(Provider, Generic[T]):
provided_type = Optional[Type]
def __init__(self, provides: _Callable[..., T], *args: Injection, **kwargs: Injection) -> None: ...
def __call__(self, *args: Injection, **kwargs: Injection) -> T: ...
@property
def cls(self) -> T: ...
@property
@ -247,6 +249,18 @@ class SingletonDelegate(Delegate):
def __init__(self, factory: BaseSingleton): ...
class List(Provider):
def __init__(self, *args: Injection): ...
def __call__(self, *args: Injection, **kwargs: Injection) -> _List[Any]: ...
@property
def provided(self) -> ProvidedInstance: ...
@property
def args(self) -> Tuple[Injection]: ...
def add_args(self, *args: Injection) -> List: ...
def set_args(self, *args: Injection) -> List: ...
def clear_args(self) -> List: ...
class ProvidedInstanceFluentInterface:
def __getattr__(self, item: str) -> AttributeGetter: ...
def __getitem__(self, item: str) -> ItemGetter: ...

29
tests/typing/list.py Normal file
View File

@ -0,0 +1,29 @@
from typing import Tuple, Any, List
from dependency_injector import providers
# Test 1: to check the return type (class)
provider1 = providers.List(
providers.Factory(object),
providers.Factory(object),
)
var1: List[Any] = provider1()
# Test 2: to check the .args attributes
provider2 = providers.List(
providers.Factory(object),
providers.Factory(object),
)
args2: Tuple[Any] = provider2.args
# Test 5: to check the provided instance interface
provider3 = providers.List(
providers.Factory(object),
providers.Factory(object),
)
provided3: providers.ProvidedInstance = provider3.provided
attr_getter3: providers.AttributeGetter = provider3.provided.attr
item_getter3: providers.ItemGetter = provider3.provided['item']
method_caller3: providers.MethodCaller = provider3.provided.method.call(123, arg=324)