Improve FactoryAggregate typing stub

This commit is contained in:
Roman Mogylatov 2021-08-25 08:48:03 -04:00
parent 6af818102b
commit 4cb268a352
3 changed files with 15 additions and 14 deletions

View File

@ -9,6 +9,7 @@ follows `Semantic versioning`_
Development version Development version
------------------- -------------------
- Improve ``FactoryAggregate`` typing stub.
- Improve resource subclasses typing and make shutdown definition optional - Improve resource subclasses typing and make shutdown definition optional
`PR #492 <https://github.com/ets-labs/python-dependency-injector/pull/492>`_. `PR #492 <https://github.com/ets-labs/python-dependency-injector/pull/492>`_.
Thanks to `@EdwardBlair <https://github.com/EdwardBlair>`_ for suggesting the improvement. Thanks to `@EdwardBlair <https://github.com/EdwardBlair>`_ for suggesting the improvement.

View File

@ -282,19 +282,19 @@ class FactoryDelegate(Delegate):
def __init__(self, factory: Factory): ... def __init__(self, factory: Factory): ...
class FactoryAggregate(Provider): class FactoryAggregate(Provider[T]):
def __init__(self, **factories: Factory): ... def __init__(self, **factories: Factory[T]): ...
def __getattr__(self, factory_name: str) -> Factory: ... def __getattr__(self, factory_name: str) -> Factory[T]: ...
@overload @overload
def __call__(self, factory_name: str, *args: Injection, **kwargs: Injection) -> Any: ... def __call__(self, factory_name: str, *args: Injection, **kwargs: Injection) -> T: ...
@overload @overload
def __call__(self, factory_name: str, *args: Injection, **kwargs: Injection) -> Awaitable[Any]: ... def __call__(self, factory_name: str, *args: Injection, **kwargs: Injection) -> Awaitable[T]: ...
def async_(self, factory_name: str, *args: Injection, **kwargs: Injection) -> Awaitable[Any]: ... def async_(self, factory_name: str, *args: Injection, **kwargs: Injection) -> Awaitable[T]: ...
@property @property
def factories(self) -> _Dict[str, Factory]: ... def factories(self) -> _Dict[str, Factory[T]]: ...
def set_factories(self, **factories: Factory) -> FactoryAggregate: ... def set_factories(self, **factories: Factory[T]) -> FactoryAggregate[T]: ...
class BaseSingleton(Provider[T]): class BaseSingleton(Provider[T]):

View File

@ -55,13 +55,13 @@ animal7: Animal = provider7(1, 2, 3, b='1', c=2, e=0.0)
provider8 = providers.FactoryDelegate(providers.Factory(object)) provider8 = providers.FactoryDelegate(providers.Factory(object))
# Test 9: to check FactoryAggregate provider # Test 9: to check FactoryAggregate provider
provider9 = providers.FactoryAggregate( provider9: providers.FactoryAggregate[str] = providers.FactoryAggregate(
a=providers.Factory(object), a=providers.Factory(str, "str1"),
b=providers.Factory(object), b=providers.Factory(str, "str2"),
) )
factory_a_9: providers.Factory = provider9.a factory_a_9: providers.Factory[str] = provider9.a
factory_b_9: providers.Factory = provider9.b factory_b_9: providers.Factory[str] = provider9.b
val9: Any = provider9('a') val9: str = provider9('a')
# Test 10: to check the explicit typing # Test 10: to check the explicit typing
factory10: providers.Provider[Animal] = providers.Factory(Cat) factory10: providers.Provider[Animal] = providers.Factory(Cat)