From 9102d0a461cc62f80a4f247b198617c967c0d5e8 Mon Sep 17 00:00:00 2001 From: Andrey Tikhonov <17@itishka.org> Date: Wed, 6 Nov 2024 22:36:10 +0100 Subject: [PATCH] unpack provide multiple source --- src/dishka/dependency_source/make_factory.py | 5 +++++ tests/unit/container/test_alias.py | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/dishka/dependency_source/make_factory.py b/src/dishka/dependency_source/make_factory.py index d5a97cc9..deb72807 100644 --- a/src/dishka/dependency_source/make_factory.py +++ b/src/dishka/dependency_source/make_factory.py @@ -433,6 +433,11 @@ def make_factory( is_in_class: bool, override: bool, ) -> Factory: + if get_origin(source) is ProvideMultiple: + if provides is None: + provides = source + source = get_args(source)[0] + if is_bare_generic(source): source = source[get_type_vars(source)] # type: ignore[index] diff --git a/tests/unit/container/test_alias.py b/tests/unit/container/test_alias.py index 1c69f614..1fdb615b 100644 --- a/tests/unit/container/test_alias.py +++ b/tests/unit/container/test_alias.py @@ -67,6 +67,24 @@ def test_implicit(): mock.assert_called_once() + +def test_implicit_no_source(): + provider = Provider(scope=Scope.APP) + provider.provide_all(AnyOf[float, str]) + container = make_container(provider) + assert container.get(float) == 0.0 + assert container.get(str) == 0.0 + + + +def test_implicit_all(): + provider = Provider(scope=Scope.APP) + provider.provide_all(AnyOf[float, str]) + container = make_container(provider) + assert container.get(float) == 0.0 + assert container.get(str) == 0.0 + + def test_implicit_generator(): class MyProvider(Provider): value = 0