In Python 3.5, how can I specify a function as a t

2019-02-23 19:04发布

What is the appropriate type hint to specify that a variable should be a function (the equivalent of a delegate, Func<T> or Action in C#)?

Is it also possible to specify the function argument types in a generic fashion as well (for example Func<int, int>)?

I cannot find any relevant details in the documentation.

1条回答
forever°为你锁心
2楼-- · 2019-02-23 19:38

According to the docs, you can use Callable, imported from typing.

You can view more details in PEP 0484.

查看更多
登录 后发表回答