I have seen typing.Callable
, but I didn't find any useful docs about it. What exactly is typing.Callable
?
typing.Callable
is the type you use to indicate a callable. Most python types that support the ()
operator are of the type collections.abc.Callable
. Examples include functions, classmethod
s, staticmethod
s, bound methods and lambdas.
In summary, anything with a __call__
method (which is how ()
is implemented), is a callable.
PEP 677 attempted to introduce implicit tuple-with-arrow syntax, so that something like Callable[[int, str], list[float]]
could be expressed much more intuitively as (int, str) -> list[float]
. The PEP was rejected because the benefits of the new syntax were not deemed sufficient given the added maintenance burden and possible room for confusion.