Search code examples
pythontype-hinting

Type hinting function with function argument


Consider the following function:

def test(data: np.ndarray, func, *args) -> np.ndarray:
    return func(data, args)

The func and args arguments are numpy function and arguments corresponding to it. The question is, how do i annotate these two arguments with type hinting?


Solution

  • typing.Callable springs to mind for the func argument.

    As for *args - whilst it can be type hinted, I'd question the value of doing so. After all, it's an arbitrary set of positional arguments.

    However, if you insist on doing so, then *args is of type typing.Tuple