Is it just callable
? In the meantime I have been using function
as my IDE regards callable
as a bool
.
def func(a: int, b: str, callback: ???)
Type hinting is a formal solution to statically indicate the type of a value within your Python code. It was specified in PEP 484 and introduced in Python 3.5.
The name of this function is Python type(). Python type() function is a built-in function in python that allows the programmer to evaluate the type of data used in the program for every variable.
What Are Type Annotations? Type annotations — also known as type signatures — are used to indicate the datatypes of variables and input/outputs of functions and methods. In many languages, datatypes are explicitly stated. In these languages, if you don't declare your datatype — the code will not run.
In a type hint, if we specify a type (class), then we mark the variable as containing an instance of that type. To specify that a variable instead contains a type, we need to use type[Cls] (or the old syntax typing. Type ).
Yes, typing.Callable
is the right hint for a callback.
Also see the Callable section of PEP 484:
Frameworks expecting callback functions of specific signatures might be type hinted using
Callable[[Arg1Type, Arg2Type], ReturnType]
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With