How to annotate ruturn type or attribute type “functiontype”?
expectations:
def _(function: functiontype) -> functiontype:
return function
The type()
used on any function returns <class 'function'>
. The question is, where to import <class 'function'>
from.
3
For type hints, functions can be annotated using collections.abc.Callable or typing.Callable
https://docs.python.org/3/library/typing.html#annotating-callable-objects
For example, Callable[[int], str]
signifies a function that takes a single parameter of type int
and returns a str
.