ctypes: improve bytes handling (#9029)

This commit is contained in:
Jelle Zijlstra
2022-10-31 07:26:09 -07:00
committed by GitHub
parent ae75d68fe9
commit 3d8d744eb4
2 changed files with 8 additions and 2 deletions

View File

@@ -194,7 +194,7 @@ class _SimpleCData(Generic[_T], _CData):
class c_byte(_SimpleCData[int]): ...
class c_char(_SimpleCData[bytes]):
def __init__(self, value: int | bytes = ...) -> None: ...
def __init__(self, value: int | bytes | bytearray = ...) -> None: ...
class c_char_p(_PointerLike, _SimpleCData[bytes | None]):
def __init__(self, value: int | bytes | None = ...) -> None: ...
@@ -266,7 +266,11 @@ class Array(Generic[_CT], _CData):
def _type_(self) -> type[_CT]: ...
@_type_.setter
def _type_(self, value: type[_CT]) -> None: ...
raw: bytes # Note: only available if _CT == c_char
# Note: only available if _CT == c_char
@property
def raw(self) -> bytes: ...
@raw.setter
def raw(self, value: ReadableBuffer) -> None: ...
value: Any # Note: bytes if _CT == c_char, str if _CT == c_wchar, unavailable otherwise
# TODO These methods cannot be annotated correctly at the moment.
# All of these "Any"s stand for the array's element type, but it's not possible to use _CT

View File

@@ -367,6 +367,8 @@ _ctypes.sizeof
# Allowlist entries that cannot or should not be fixed
# ==========
ctypes.Array.raw # exists but stubtest can't see it; only available if _CT == c_char
_collections_abc.AsyncGenerator.asend # async at runtime, deliberately not in the stub, see #7491. Pos-only differences also.
_collections_abc.AsyncGenerator.__anext__ # async at runtime, deliberately not in the stub, see #7491
_collections_abc.AsyncGenerator.aclose # async at runtime, deliberately not in the stub, see #7491