From b4ac08819ecccb276f580ac7ac16aae2fed807fc Mon Sep 17 00:00:00 2001 From: Roman Mogylatov Date: Fri, 5 Feb 2021 17:49:16 -0500 Subject: [PATCH] Improve .traverse() typing stubs --- docs/main/changelog.rst | 5 +++++ src/dependency_injector/containers.pyi | 5 +++-- src/dependency_injector/providers.pyi | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/docs/main/changelog.rst b/docs/main/changelog.rst index cddda4af..175491a5 100644 --- a/docs/main/changelog.rst +++ b/docs/main/changelog.rst @@ -7,6 +7,11 @@ that were made in every particular version. From version 0.7.6 *Dependency Injector* framework strictly follows `Semantic versioning`_ +Development version +------------------- +- Improve ``container.traverse(types=[...])`` and ``provider.traverse(types=[...])`` typing stubs + to return ``types`` -typed iterator. + 4.18.0 ------ - Add ``container.reset_singleton()`` method to reset container singletons. diff --git a/src/dependency_injector/containers.pyi b/src/dependency_injector/containers.pyi index c0ccfdc8..031a575e 100644 --- a/src/dependency_injector/containers.pyi +++ b/src/dependency_injector/containers.pyi @@ -21,6 +21,7 @@ from .providers import Provider C_Base = TypeVar('C_Base', bound='Container') C = TypeVar('C', bound='DeclarativeContainer') C_Overriding = TypeVar('C_Overriding', bound='DeclarativeContainer') +TT = TypeVar('TT') class Container: @@ -46,10 +47,10 @@ class Container: def apply_container_providers_overridings(self) -> None: ... def reset_singletons(self) -> None: ... @overload - def traverse(self, types: Optional[Sequence[Type]] = None) -> Iterator[Provider]: ... + def traverse(self, types: Optional[Sequence[TT]] = None) -> Iterator[TT]: ... @classmethod @overload - def traverse(cls, types: Optional[Sequence[Type]] = None) -> Iterator[Provider]: ... + def traverse(cls, types: Optional[Sequence[TT]] = None) -> Iterator[TT]: ... class DynamicContainer(Container): ... diff --git a/src/dependency_injector/providers.pyi b/src/dependency_injector/providers.pyi index 7ca11bf9..abcebd74 100644 --- a/src/dependency_injector/providers.pyi +++ b/src/dependency_injector/providers.pyi @@ -36,6 +36,7 @@ from . import resources Injection = Any T = TypeVar('T') +TT = TypeVar('TT') class OverridingContext: @@ -76,7 +77,7 @@ class Provider(Generic[T]): def is_async_mode_undefined(self) -> bool: ... @property def related(self) -> _Iterator[Provider]: ... - def traverse(self, types: Optional[_Iterable[Type]] = None) -> _Iterator[Provider]: ... + def traverse(self, types: Optional[_Iterable[TT]] = None) -> _Iterator[TT]: ... def _copy_overridings(self, copied: Provider, memo: Optional[_Dict[Any, Any]]) -> None: ...