Skip to content

Commit d8f8212

Browse files
authored
refactor: use inspect.is_coroutine_callable (#239)
1 parent 7270113 commit d8f8212

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

fast_depends/utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import asyncio
21
import functools
32
import inspect
43
import sys
@@ -203,11 +202,11 @@ def is_coroutine_callable(call: Callable[..., Any]) -> bool:
203202
if inspect.isclass(call):
204203
return False
205204

206-
if asyncio.iscoroutinefunction(call):
205+
if inspect.iscoroutinefunction(call):
207206
return True
208207

209208
dunder_call = getattr(call, "__call__", None) # noqa: B004
210-
return asyncio.iscoroutinefunction(dunder_call)
209+
return inspect.iscoroutinefunction(dunder_call)
211210

212211

213212
async def async_map(

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ license-files = ["LICENSE"]
1717

1818
keywords = ["fastapi", "dependency injection"]
1919

20-
version = "3.0.4"
20+
version = "3.0.5"
2121

2222
requires-python = ">=3.10"
2323

tests/test_utils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from unittest.mock import AsyncMock
2+
3+
from fast_depends.utils import is_coroutine_callable
4+
5+
6+
def test_is_coroutine_callable() -> None:
7+
async def coroutine_func() -> int:
8+
return 1
9+
10+
assert is_coroutine_callable(coroutine_func)
11+
12+
def sync_func() -> int:
13+
return 1
14+
15+
assert not is_coroutine_callable(sync_func)
16+
17+
assert is_coroutine_callable(AsyncMock())

0 commit comments

Comments
 (0)