Python type hinting for async function as function argument

You are looking for:

FuncType = Callable[[Any, Any], Awaitable[Any]]
def consumer(function_: FuncType = None):
    pass  # TODO: do stuff

Why is the type structured like that? If you declare a function async, what you actually do is wrap it in a new function with the given parameters, which returns a Coroutine.


Since this might be relevant to some people who come here, this is an example of an awaitable function type with in and out typed:

OnAction = Callable[[Foo, Bar], Awaitable[FooBar]]

It is a function that takes Foo, Bar and returns a FooBar

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)