Python 3.x 类型提示和ctypes外部函数
如何键入用Python的Python 3.x 类型提示和ctypes外部函数,python-3.x,ctypes,type-hinting,mypy,Python 3.x,Ctypes,Type Hinting,Mypy,如何键入用Python的ctypes定义的外部函数 是否需要重复restype和argtypes属性中提供的信息?或者有没有一种方法可以让mypy以某种方式理解这些属性 例如,给定此函数定义: # Original function definition: libopus.opus_encode.restype = opus_int32 libopus.opus_encode.argtypes = [oe_p, opus_int16_p, c_int, c_uchar_
ctypes
定义的外部函数
是否需要重复restype
和argtypes
属性中提供的信息?或者有没有一种方法可以让mypy以某种方式理解这些属性
例如,给定此函数定义:
# Original function definition:
libopus.opus_encode.restype = opus_int32
libopus.opus_encode.argtypes = [oe_p, opus_int16_p, c_int, c_uchar_p, opus_int32]
def opus_encode(st, pcm, frame_size, data, max_data_bytes):
return libopus.opus_encode(st, pcm, frame_size, data, max_data_bytes)
手动复制类型信息的最佳方法是什么
# Duplicated type specification:
libopus.opus_encode.restype = opus_int32
libopus.opus_encode.argtypes = [oe_p, opus_int16_p, c_int, c_uchar_p, opus_int32]
def opus_encode(st: oe_p,
pcm: opus_int16_p,
frame_size: c_int,
data: c_uchar_p,
max_data_bytes: opus_int32) -> opus_int32:
return libopus.opus_encode(st, pcm, frame_size, data, max_data_bytes)
还是有更好的方法