mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-07-09 06:43:13 +03:00
Add stub for the List provider
This commit is contained in:
parent
3092b9d8f5
commit
5100f13bff
|
@ -7,6 +7,7 @@ from typing import (
|
||||||
Callable as _Callable,
|
Callable as _Callable,
|
||||||
Any,
|
Any,
|
||||||
Tuple,
|
Tuple,
|
||||||
|
List as _List,
|
||||||
Optional,
|
Optional,
|
||||||
Dict,
|
Dict,
|
||||||
Union,
|
Union,
|
||||||
|
@ -199,6 +200,7 @@ class FactoryAggregate(Provider):
|
||||||
class BaseSingleton(Provider, Generic[T]):
|
class BaseSingleton(Provider, Generic[T]):
|
||||||
provided_type = Optional[Type]
|
provided_type = Optional[Type]
|
||||||
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: ...
|
||||||
@property
|
@property
|
||||||
def cls(self) -> T: ...
|
def cls(self) -> T: ...
|
||||||
@property
|
@property
|
||||||
|
@ -247,6 +249,18 @@ class SingletonDelegate(Delegate):
|
||||||
def __init__(self, factory: BaseSingleton): ...
|
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:
|
class ProvidedInstanceFluentInterface:
|
||||||
def __getattr__(self, item: str) -> AttributeGetter: ...
|
def __getattr__(self, item: str) -> AttributeGetter: ...
|
||||||
def __getitem__(self, item: str) -> ItemGetter: ...
|
def __getitem__(self, item: str) -> ItemGetter: ...
|
||||||
|
|
29
tests/typing/list.py
Normal file
29
tests/typing/list.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user