|
22 | 22 | from __future__ import annotations |
23 | 23 |
|
24 | 24 | from asyncio import iscoroutine |
25 | | -from typing import TYPE_CHECKING, overload, cast |
| 25 | +from typing import TYPE_CHECKING, cast, overload |
26 | 26 |
|
27 | 27 | if TYPE_CHECKING: |
28 | | - from typing import Callable, Final, TypeVar, Coroutine, Any |
| 28 | + from typing import Any, Callable, Coroutine, Final, TypeVar |
| 29 | + |
29 | 30 | from typing_extensions import ParamSpec |
30 | 31 |
|
31 | 32 | P = ParamSpec("P") |
32 | 33 | T = TypeVar("T") |
33 | 34 |
|
34 | 35 | __all__: Final[tuple[str, ...]] = ("maybe_coro",) |
35 | 36 |
|
| 37 | + |
36 | 38 | @overload |
37 | 39 | async def maybe_coro(coro: Callable[P, Coroutine[Any, Any, T]], *args: P.args, **kwargs: P.kwargs) -> T: |
38 | 40 | ... |
39 | 41 |
|
| 42 | + |
40 | 43 | @overload |
41 | 44 | async def maybe_coro(coro: Callable[P, T], *args: P.args, **kwargs: P.kwargs) -> T: |
42 | 45 | ... |
@@ -66,5 +69,5 @@ async def maybe_coro(coro: Callable[P, T | Coroutine[Any, Any, T]], *args: P.arg |
66 | 69 | return await result |
67 | 70 |
|
68 | 71 | # Not a async function, just return the result |
69 | | - result = cast("T", result) # The case where this is Coroutine[Any, Any, T] is handled by iscouroutine. |
| 72 | + result = cast("T", result) # The case where this is Coroutine[Any, Any, T] is handled by iscouroutine. |
70 | 73 | return result |
0 commit comments