Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow to inject async functions into async generators #124

Merged
merged 4 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fast_depends/core/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def build_call_model(

is_call_async = is_coroutine_callable(call)
if is_sync is None:
is_sync = not is_call_async
is_sync = not is_call_async and not inspect.isasyncgenfunction(call)
Lancetnik marked this conversation as resolved.
Show resolved Hide resolved
else:
assert not (
is_sync and is_call_async
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