函数的类型提示是什么[重复]

问题描述 投票:0回答:1

只是

callable
吗?与此同时,我一直在使用
function
,因为我的 IDE 将
callable
视为
bool

def func(a: int, b: str, callback: ???)
python python-typing
1个回答
29
投票

是的,

typing.Callable
是回调的正确提示。

另请参阅 PEP 484 的 Callable 部分

需要特定签名的回调函数的框架可能会使用

Callable[[Arg1Type, Arg2Type], ReturnType]
进行类型提示。

© www.soinside.com 2019 - 2024. All rights reserved.