【发布时间】:2016-10-16 13:17:01
【问题描述】:
我想在我当前的 Python 3.5 项目中使用类型提示。我的函数应该接收一个函数作为参数。
如何在类型提示中指定类型函数?
import typing
def my_function(name:typing.AnyStr, func: typing.Function) -> None:
# However, typing.Function does not exist.
# How can I specify the type function for the parameter `func`?
# do some processing
pass
我检查了PEP 483,但在那里找不到函数类型提示。
【问题讨论】:
-
一个函数是
Callable -
python.org/dev/peps/pep-0483/#fundamental-building-blocks,“我们可能会添加”之前的最后一个要点。
标签: python python-3.x type-hinting mypy python-typing