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?

Viewed 141

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?

2 Answers

According to Python Documentation

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

It's very hard to tell what this function would take as input and output without any information about the class, or what the class does. It completely depends on what the class does, and you should probably read the documentation of the class.
From looking at the default value of extension, the class expects .jpg files. If it is a graphics or image manipulation library like pillow, the callable may need to take image data of some kind.
As I said, however, it's impossible to tell without more information.

Related