Skip to content

Commit

Permalink
fix: Allow to inject async functions into async generators (#124)
Browse files Browse the repository at this point in the history
Co-authored-by: Pastukhov Nikita <nikita@pastukhov-dev.ru>
  • Loading branch information
Zhenay and Lancetnik authored Aug 22, 2024
1 parent bca8970 commit 5eeb685
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion fast_depends/core/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def build_call_model(
) -> CallModel[P, T]:
name = getattr(call, "__name__", type(call).__name__)

is_call_async = is_coroutine_callable(call)
is_call_async = is_coroutine_callable(call) or is_async_gen_callable(call)
if is_sync is None:
is_sync = not is_call_async
else:
Expand Down
10 changes: 9 additions & 1 deletion tests/async/test_depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,19 @@ async def test_generator():
mock = Mock()

async def func():
mock.async_call()

async def gen_func():
mock.start()
yield
mock.end()

@inject
async def simple_func(a: str, d=Depends(func)) -> int:
async def simple_func(
a: str,
d=Depends(gen_func),
d2=Depends(func),
) -> int:
for _ in range(2):
yield a

Expand All @@ -436,6 +443,7 @@ async def simple_func(a: str, d=Depends(func)) -> int:
assert not mock.end.called
assert i == 1

mock.async_call.assert_called_once()
mock.end.assert_called_once()


Expand Down

0 comments on commit 5eeb685

Please sign in to comment.