pythonpython-typingcallable

In python typing in the Class method __init__ the argument type annotation I have for 1 attribute is: Callable = None, what does the annotation state?


The init function inside a Class is annotated the following way:

    def __init__(self, directory: str, transforms: Callable = None, extension: str = '.jpg'):

The question is what Callable = None is referring to.

Conventionally if the transforms - argument annotation would mean to intake a Callable (i.e. a function) then the input parameters would need to be defined as well as the output, as an example it could be: transforms: Callable[[int,int], int] where the [int,int] would be the function parameters as input, and the latter int` would be the return. But here this is not the case.

What does the Callableannotation expect as input and return in this case?


Solution

  • According to Python Documentation

    A plain Callable is equivalent to Callable[..., Any], and in turn to collections.abc.Callable.