mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-12-01 05:53:59 +03:00
Update typing and add typing tests
This commit is contained in:
parent
109dd8b761
commit
87a033c075
|
@ -158,10 +158,10 @@ class DependenciesContainer(Object):
|
|||
|
||||
|
||||
class Callable(Provider[T]):
|
||||
def __init__(self, provides: Optional[_Callable[..., T]] = None, *args: Injection, **kwargs: Injection) -> None: ...
|
||||
def __init__(self, provides: Optional[Union[_Callable[..., T], str]] = None, *args: Injection, **kwargs: Injection) -> None: ...
|
||||
@property
|
||||
def provides(self) -> Optional[_Callable[..., T]]: ...
|
||||
def set_provides(self, provides: Optional[_Callable[..., T]]) -> Callable[T]: ...
|
||||
def set_provides(self, provides: Optional[Union[_Callable[..., T], str]]) -> Callable[T]: ...
|
||||
@property
|
||||
def args(self) -> Tuple[Injection]: ...
|
||||
def add_args(self, *args: Injection) -> Callable[T]: ...
|
||||
|
@ -283,12 +283,12 @@ class Configuration(Object[Any]):
|
|||
|
||||
class Factory(Provider[T]):
|
||||
provided_type: Optional[Type]
|
||||
def __init__(self, provides: Optional[_Callable[..., T]] = None, *args: Injection, **kwargs: Injection) -> None: ...
|
||||
def __init__(self, provides: Optional[Union[_Callable[..., T], str]] = None, *args: Injection, **kwargs: Injection) -> None: ...
|
||||
@property
|
||||
def cls(self) -> Type[T]: ...
|
||||
@property
|
||||
def provides(self) -> Optional[_Callable[..., T]]: ...
|
||||
def set_provides(self, provides: Optional[_Callable[..., T]]) -> Factory[T]: ...
|
||||
def set_provides(self, provides: Optional[Union[_Callable[..., T], str]]) -> Factory[T]: ...
|
||||
@property
|
||||
def args(self) -> Tuple[Injection]: ...
|
||||
def add_args(self, *args: Injection) -> Factory[T]: ...
|
||||
|
@ -326,12 +326,12 @@ class FactoryAggregate(Aggregate[T]):
|
|||
|
||||
class BaseSingleton(Provider[T]):
|
||||
provided_type = Optional[Type]
|
||||
def __init__(self, provides: Optional[_Callable[..., T]] = None, *args: Injection, **kwargs: Injection) -> None: ...
|
||||
def __init__(self, provides: Optional[Union[_Callable[..., T], str]] = None, *args: Injection, **kwargs: Injection) -> None: ...
|
||||
@property
|
||||
def cls(self) -> Type[T]: ...
|
||||
@property
|
||||
def provides(self) -> Optional[_Callable[..., T]]: ...
|
||||
def set_provides(self, provides: Optional[_Callable[..., T]]) -> BaseSingleton[T]: ...
|
||||
def set_provides(self, provides: Optional[Union[_Callable[..., T], str]]) -> BaseSingleton[T]: ...
|
||||
@property
|
||||
def args(self) -> Tuple[Injection]: ...
|
||||
def add_args(self, *args: Injection) -> BaseSingleton[T]: ...
|
||||
|
@ -377,7 +377,7 @@ class AbstractSingleton(BaseSingleton[T]):
|
|||
|
||||
|
||||
class SingletonDelegate(Delegate):
|
||||
def __init__(self, factory: BaseSingleton): ...
|
||||
def __init__(self, singleton: BaseSingleton): ...
|
||||
|
||||
|
||||
class List(Provider[_List]):
|
||||
|
@ -410,7 +410,7 @@ class Resource(Provider[T]):
|
|||
@overload
|
||||
def __init__(self, provides: Optional[_Callable[..., _Coroutine[Injection, Injection, T]]] = None, *args: Injection, **kwargs: Injection) -> None: ...
|
||||
@overload
|
||||
def __init__(self, provides: Optional[_Callable[..., T]] = None, *args: Injection, **kwargs: Injection) -> None: ...
|
||||
def __init__(self, provides: Optional[Union[_Callable[..., T], str]] = None, *args: Injection, **kwargs: Injection) -> None: ...
|
||||
@property
|
||||
def provides(self) -> Optional[_Callable[..., Any]]: ...
|
||||
def set_provides(self, provides: Optional[Any]) -> Resource[T]: ...
|
||||
|
|
|
@ -66,3 +66,7 @@ assert provides10 is Cat
|
|||
provider11 = providers.Callable[Animal](Cat)
|
||||
provides11: Optional[Callable[..., Animal]] = provider11.provides
|
||||
assert provides11 is Cat
|
||||
|
||||
# Test 12: to check string imports
|
||||
provider12: providers.Callable[dict] = providers.Callable("builtins.dict")
|
||||
provider12.set_provides("builtins.dict")
|
||||
|
|
|
@ -9,3 +9,7 @@ async def _coro() -> None:
|
|||
# Test 1: to check the return type
|
||||
provider1 = providers.Coroutine(_coro)
|
||||
var1: Coroutine = provider1()
|
||||
|
||||
# Test 2: to check string imports
|
||||
provider2: providers.Coroutine[None] = providers.Coroutine("_coro")
|
||||
provider2.set_provides("_coro")
|
||||
|
|
|
@ -99,3 +99,7 @@ provided_cls13: Type[Animal] = provider13.cls
|
|||
assert issubclass(provided_cls13, Animal)
|
||||
provided_provides13: Optional[Callable[..., Animal]] = provider13.provides
|
||||
assert provided_provides13 is not None and provided_provides13() == Cat()
|
||||
|
||||
# Test 14: to check string imports
|
||||
provider14: providers.Factory[dict] = providers.Factory("builtins.dict")
|
||||
provider14.set_provides("builtins.dict")
|
||||
|
|
|
@ -97,3 +97,8 @@ provider8 = providers.Resource(MyResource8)
|
|||
async def _provide8() -> None:
|
||||
var1: List[int] = await provider8() # type: ignore
|
||||
var2: List[int] = await provider8.async_()
|
||||
|
||||
|
||||
# Test 9: to check string imports
|
||||
provider9: providers.Resource[dict] = providers.Resource("builtins.dict")
|
||||
provider9.set_provides("builtins.dict")
|
||||
|
|
|
@ -89,3 +89,7 @@ provided_cls15: Type[Animal] = provider15.cls
|
|||
assert issubclass(provided_cls15, Animal)
|
||||
provided_provides15: Optional[Callable[..., Animal]] = provider15.provides
|
||||
assert provided_provides15 is not None and provided_provides15() == Cat()
|
||||
|
||||
# Test 16: to check string imports
|
||||
provider16: providers.Singleton[dict] = providers.Singleton("builtins.dict")
|
||||
provider16.set_provides("builtins.dict")
|
||||
|
|
Loading…
Reference in New Issue
Block a user