相关疑难解决方法(0)

如何在类型提示中指定函数类型?

我想在我当前的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
Run Code Online (Sandbox Code Playgroud)

我检查了PEP 483,但在那里找不到函数类型提示.

python type-hinting python-3.x python-3.5 mypy

91
推荐指数
3
解决办法
2万
查看次数

标签 统计

mypy ×1

python ×1

python-3.5 ×1

python-3.x ×1

type-hinting ×1