python官网对于Callable的说明:
1.Frameworks expecting callback functions of specific signatures might be type hinted using Callable[[Arg1Type, Arg2Type], ReturnType].
期待信号回调函数的框架可以被简写为Callable[[Arg1Type, Arg2Type], ReturnType].
2.Callable[[int], str] is a function of (int) -> str.
Callable[[int], str] 是一个入参类型为int,返回值为str的函数
3.The subscription syntax must always be used with exactly two values: the argument list and the return type. The argument list must be a list of types or an ellipsis; the return type must be a single type.
这种写法必须使用两个确定的值才能使用,即参数列表和返回类型。参数列表是必须是一组类型或一个省略号...,返回类型必须是一个单值。
所以,f: Callable[[T], Iterable[U]]表示入参f是一个入参为T,返回值为Iterable[U]类型的函数即
a function to turn a T into a sequence of U(将一个T转换为一个U序列的函数)
本文介绍了Python中的Callable类型,用于指定期望特定签名的回调函数,包括参数列表的要求(可以是类型列表或省略号)和返回类型的单一性。它展示了如何用`Callable[[T],Iterable[U]]`来表示将T转换为U序列的函数。
1400

被折叠的 条评论
为什么被折叠?



