File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed
Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -46,9 +46,16 @@ def is_coro(
4646 func_or_obj : config .CallbackType ,
4747) -> "TypeGuard[Callable[..., Coroutine[Any, Any, Any]]]" :
4848 """Tests if a function is a coroutine function or a callable coroutine object."""
49- # Until Python 3.10, inspect.iscoroutinefunction() will fail to identify AsyncMocks
50- # as coroutines: https://github.com/python/cpython/issues/84753
51- # Use asyncio.iscoroutinefunction() instead.
49+ # Workaround for CPython issue #84753 in Python 3.9 and older
50+ # c.f.: https://github.com/python/cpython/issues/84753
51+ if sys .version_info < (3 , 10 ):
52+ from unittest .mock import AsyncMock
53+
54+ if isinstance (func_or_obj , AsyncMock ) or (
55+ callable (func_or_obj ) and isinstance (getattr (func_or_obj , "__call__" , None ), AsyncMock )
56+ ):
57+ return True
58+
5259 return inspect .iscoroutinefunction (func_or_obj ) or (
5360 callable (func_or_obj ) and inspect .iscoroutinefunction (func_or_obj .__call__ ) # type: ignore
5461 )
You can’t perform that action at this time.
0 commit comments