ctypes的类型提示

问题描述 投票:0回答:1

我可以输入提示ctype类型吗?

from ctypes import *

def wrap_function(library: str, name: str, restype, argtypes) -> *What goes here*:
    """Simplify wrapping ctypes functions"""
    func = library.__getattr__(name)
    func.restype = restype
    func.argtypes = argtypes
    return func
在获得<_FuncPtr object at 0x--------->之前创建的

检查ctypes函数。如何在python中指出呢?

我尝试过

ctypes.POINTER(ctypes.CFUNCTYPE)

但失败了

Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: must be a ctypes type
python ctypes type-hinting
1个回答
0
投票

CFUNCTYPE是函数原型,而不是ctypes类型。您可以使用CFUNCTYPE定义函数类型,然后将其包装在指针中,例如

from ctypes import *
POINTER(CFUNCTYPE(c_int, POINTER(c_int), POINTER(c_int)))

您可以使用定义的类型来键入提示

© www.soinside.com 2019 - 2024. All rights reserved.