Created
November 19, 2024 12:50
-
-
Save FMeinicke/c020efecb1f43fc1043f8d327c32d085 to your computer and use it in GitHub Desktop.
An implementation of `functools.partial()` for async functions.
This file contains hidden or 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
| async def async_partial(func: Callable[..., Any], *args: Any, **kwargs: Any) -> Callable[..., Any]: | |
| """ | |
| Partially apply the given `args` and `kwargs` to the given asynchronous function `func`. | |
| Parameters | |
| ---------- | |
| func : callable | |
| The asynchronous function to partially apply the arguments to | |
| args : Any | |
| The positional arguments to apply | |
| kwargs : Any | |
| The keyword arguments to apply | |
| Returns | |
| ------- | |
| callable | |
| The partially applied asynchronous function | |
| """ | |
| async def inner(*fargs: Any, **fkwargs: Any) -> Any: | |
| return await func(*args, *fargs, **kwargs, **fkwargs) | |
| return inner |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment