From c4639e555ea5a2c84362dd5eef1460fd4513e6f2 Mon Sep 17 00:00:00 2001 From: Roman Mogylatov Date: Wed, 11 Aug 2021 21:23:18 -0400 Subject: [PATCH] Add typing fix for container.override_providers() --- docs/main/changelog.rst | 1 + src/dependency_injector/containers.pyi | 2 +- tests/typing/declarative_container.py | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/main/changelog.rst b/docs/main/changelog.rst index 45021391..672b14dc 100644 --- a/docs/main/changelog.rst +++ b/docs/main/changelog.rst @@ -12,6 +12,7 @@ Dev version - Fix ``@containers.copy()`` decorator to respect dependencies on parent providers. See issue `#477 `_. Thanks to `Andrey Torsunov @gtors `_ for reporting the issue. +- Fix typing stub for ``container.override_providers()`` to accept other types besides ``Provider``. 4.35.2 ------ diff --git a/src/dependency_injector/containers.pyi b/src/dependency_injector/containers.pyi index af398e3b..1357f2f1 100644 --- a/src/dependency_injector/containers.pyi +++ b/src/dependency_injector/containers.pyi @@ -40,7 +40,7 @@ class Container: def set_providers(self, **providers: Provider): ... def set_provider(self, name: str, provider: Provider) -> None: ... def override(self, overriding: C_Base) -> None: ... - def override_providers(self, **overriding_providers: Provider) -> None: ... + def override_providers(self, **overriding_providers: Union[Provider, Any]) -> None: ... def reset_last_overriding(self) -> None: ... def reset_override(self) -> None: ... def wire(self, modules: Optional[Iterable[Any]] = None, packages: Optional[Iterable[Any]] = None) -> None: ... diff --git a/tests/typing/declarative_container.py b/tests/typing/declarative_container.py index b5922e77..51356514 100644 --- a/tests/typing/declarative_container.py +++ b/tests/typing/declarative_container.py @@ -56,3 +56,11 @@ class Container6(containers.DeclarativeContainer): container6: containers.Container = Container6() + + +# Test 7: to override() +class Container7(containers.DeclarativeContainer): + provider = providers.Factory(str) + +container7 = Container7() +container7.override_providers(provider='new_value')