Skip to content

Instantly share code, notes, and snippets.

@FMeinicke
Created November 19, 2024 12:50
Show Gist options
  • Select an option

  • Save FMeinicke/c020efecb1f43fc1043f8d327c32d085 to your computer and use it in GitHub Desktop.

Select an option

Save FMeinicke/c020efecb1f43fc1043f8d327c32d085 to your computer and use it in GitHub Desktop.
An implementation of `functools.partial()` for async functions.
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