Skip to content

Commit

Permalink
Merge pull request #345 from K1rL3s/fix-provide-all
Browse files Browse the repository at this point in the history
fix `provide_all`: wrong `provides=` value
  • Loading branch information
Tishka17 authored Jan 18, 2025
2 parents 62a2c85 + 84cac93 commit 044575b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/dishka/dependency_source/make_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ def _provide_all(
for single_provides in provides:
source = _provide(
source=single_provides,
provides=single_provides,
provides=None,
scope=scope,
cache=cache,
is_in_class=is_in_class,
Expand Down
42 changes: 41 additions & 1 deletion tests/unit/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest

from dishka import Provider, Scope, alias, decorate, provide
from dishka import Provider, Scope, alias, decorate, make_container, provide
from dishka.dependency_source.make_factory import make_factory, provide_all
from dishka.entities.factory_type import FactoryType
from dishka.entities.key import (
Expand Down Expand Up @@ -306,3 +306,43 @@ def decorator(param: int) -> str:

with pytest.raises(ValueError): # noqa: PT011
decorate(decorator)


def test_provide_all_as_provider_method():
def a() -> int:
return 100

def b(num: int) -> float:
return num / 2

provider = Provider(scope=Scope.APP)
provider.provide_all(a, b)

container = make_container(provider)

hundred = container.get(int)
assert hundred == 100

fifty = container.get(float)
assert fifty == 50.0


def test_provide_all_in_class():
class MyProvider(Provider):
scope = Scope.APP

def a(self) -> int:
return 100

def b(self, num: int) -> float:
return num / 2

abcd = provide_all(a, b)

container = make_container(MyProvider())

hundred = container.get(int)
assert hundred == 100

fifty = container.get(float)
assert fifty == 50.0

0 comments on commit 044575b

Please sign in to comment.