Skip to content

Commit

Permalink
unpack provide multiple source
Browse files Browse the repository at this point in the history
  • Loading branch information
Tishka17 committed Nov 6, 2024
1 parent 3ace7db commit 9102d0a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/dishka/dependency_source/make_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
18 changes: 18 additions & 0 deletions tests/unit/container/test_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9102d0a

Please sign in to comment.