Change type hint for init_c_struct_t and to_struct [pr] (#10878)

* Change type hint for init_c_struct_t

* Change type hint for to_struct
This commit is contained in:
simone-pietro
2025-06-19 12:22:44 +02:00
committed by GitHub
parent 00d0071b36
commit 58252e3c49
2 changed files with 3 additions and 2 deletions

View File

@@ -298,7 +298,7 @@ def mv_address(mv): return ctypes.addressof(ctypes.c_char.from_buffer(mv))
def to_char_p_p(options: list[bytes], to_type=ctypes.c_char):
return (ctypes.POINTER(to_type) * len(options))(*[ctypes.cast(ctypes.create_string_buffer(o), ctypes.POINTER(to_type)) for o in options])
@functools.cache
def init_c_struct_t(fields: tuple[tuple[str, ctypes._SimpleCData], ...]):
def init_c_struct_t(fields: tuple[tuple[str, type[ctypes._SimpleCData]], ...]):
class CStruct(ctypes.Structure):
_pack_, _fields_ = 1, fields
return CStruct

View File

@@ -47,7 +47,8 @@ def msg(selector: str, restype: type[T] = objc_id): # type: ignore [assignment]
def to_ns_str(s: str): return msg("stringWithUTF8String:", objc_instance)(libobjc.objc_getClass(b"NSString"), s.encode())
def from_ns_str(s): return bytes(msg("UTF8String", ctypes.c_char_p)(s)).decode()
def to_struct(*t: int, _type: type = ctypes.c_ulong): return init_c_struct_t(tuple([(f"field{i}", _type) for i in range(len(t))]))(*t)
def to_struct(*t: int, _type: type[ctypes._SimpleCData] = ctypes.c_ulong):
return init_c_struct_t(tuple([(f"field{i}", _type) for i in range(len(t))]))(*t)
def wait_check(cbuf: Any):
msg("waitUntilCompleted")(cbuf)