-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
147 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
import functools | ||
from typing import Any, Callable, TypeVar, cast | ||
from typing import Awaitable, Any, Callable, TypeVar, Coroutine | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from typing_extensions import ParamSpec | ||
|
||
_CallableT = TypeVar("_CallableT", bound=Callable[..., Any]) | ||
P = ParamSpec("P") | ||
T = TypeVar("T") | ||
|
||
|
||
def wrap_coroutine(api: Any, coroutine: _CallableT) -> _CallableT: | ||
def wrap_coroutine(api: Any, coroutine: "Callable[P, Awaitable[T]]") -> "Callable[P, Coroutine[Any, Any, T]]": | ||
@functools.wraps(coroutine) | ||
async def wrapper(*args: Any, **kwargs: Any) -> Any: | ||
async def wrapper(*args: "P.args", **kwargs: "P.kwargs") -> T: | ||
with api as time_factory: | ||
if api.as_arg: | ||
result = await coroutine(time_factory, *args, **kwargs) | ||
else: | ||
result = await coroutine(*args, **kwargs) | ||
return result | ||
|
||
return cast(_CallableT, wrapper) | ||
return wrapper |
Oops, something went wrong.