Ser*_*tch 5 python arrays annotations function definition
考虑以下 Python 代码:
def foo(aqs : typing.List[int]) -> ??? :
array_type = ctypes.c_int64 * len(aqs)
ans = array_type(*aqs)
return ans
Run Code Online (Sandbox Code Playgroud)
这个函数的返回值的正确注释是什么?(代替???)
此函数没有一致的返回类型,因为返回数组的长度是数组类型的一部分。但是,类型始终是 的子类ctypes.Array,这是您可以使用的最具体的注释:
def foo(aqs: List[int]) -> ctypes.Array:
...
Run Code Online (Sandbox Code Playgroud)