函数的类型提示是什么
What is the type hint for a function
只是callable
吗?与此同时,我一直在使用 function
,因为我的 IDE 将 callable
视为 bool
。
def func(a: int, b: str, callback: ???)
是的,typing.Callable
是回调的正确提示。
另见 PEP 484 的 Callable section:
Frameworks expecting callback functions of specific signatures might be type hinted using Callable[[Arg1Type, Arg2Type], ReturnType]
.
只是callable
吗?与此同时,我一直在使用 function
,因为我的 IDE 将 callable
视为 bool
。
def func(a: int, b: str, callback: ???)
是的,typing.Callable
是回调的正确提示。
另见 PEP 484 的 Callable section:
Frameworks expecting callback functions of specific signatures might be type hinted using
Callable[[Arg1Type, Arg2Type], ReturnType]
.