File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change 1
1
from __future__ import annotations
2
2
3
3
import functools
4
- import inspect
5
4
import sys
6
5
from collections .abc import Awaitable , Generator
7
6
from contextlib import AbstractAsyncContextManager , contextmanager
10
9
from starlette .types import Scope
11
10
12
11
if sys .version_info >= (3 , 13 ): # pragma: no cover
12
+ from inspect import iscoroutinefunction
13
13
from typing import TypeIs
14
14
else : # pragma: no cover
15
+ from asyncio import iscoroutinefunction
16
+
15
17
from typing_extensions import TypeIs
16
18
17
19
has_exceptiongroups = True
@@ -37,7 +39,7 @@ def is_async_callable(obj: Any) -> Any:
37
39
while isinstance (obj , functools .partial ):
38
40
obj = obj .func
39
41
40
- return inspect . iscoroutinefunction (obj ) or (callable (obj ) and inspect . iscoroutinefunction (obj .__call__ ))
42
+ return iscoroutinefunction (obj ) or (callable (obj ) and iscoroutinefunction (obj .__call__ ))
41
43
42
44
43
45
T_co = TypeVar ("T_co" , covariant = True )
Original file line number Diff line number Diff line change 1
1
import functools
2
2
from typing import Any
3
+ from unittest .mock import create_autospec
3
4
4
5
import pytest
5
6
@@ -83,6 +84,13 @@ async def async_func(
83
84
assert is_async_callable (nested_partial )
84
85
85
86
87
+ def test_async_mocked_async_function () -> None :
88
+ async def async_func () -> None : ... # pragma: no cover
89
+
90
+ mock = create_autospec (async_func )
91
+ assert is_async_callable (mock )
92
+
93
+
86
94
@pytest .mark .parametrize (
87
95
"scope, expected_result" ,
88
96
[
You can’t perform that action at this time.
0 commit comments