Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I annotate a function returning a ctypes array in Python?

Consider the following Python code:

def foo(aqs : typing.List[int]) -> ??? :
    array_type = ctypes.c_int64 * len(aqs)
    ans = array_type(*aqs)
    return ans

What's the correct annotation for the return value of this function? (In place of ???)

like image 844
Serge Rogatch Avatar asked Nov 17 '22 18:11

Serge Rogatch


1 Answers

This function doesn't have a consistent return type, since the length of the returned array is part of the array's type. However, the type is always a subclass of ctypes.Array, which is the most specific annotation you can use:

def foo(aqs: List[int]) -> ctypes.Array:
    ...
like image 90
user2357112 supports Monica Avatar answered Nov 24 '22 00:11

user2357112 supports Monica