From 375bfc10ac9d20394aac9c814234069891aeb657 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 28 Oct 2022 19:11:19 -0700 Subject: [PATCH 1/3] ctypes: improve bytes handling --- stdlib/ctypes/__init__.pyi | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/stdlib/ctypes/__init__.pyi b/stdlib/ctypes/__init__.pyi index 78f4ee4d5ab3..1851d3481ee2 100644 --- a/stdlib/ctypes/__init__.pyi +++ b/stdlib/ctypes/__init__.pyi @@ -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 From d490fce9492f666616a7db73a95c168933ceecec Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 28 Oct 2022 19:26:35 -0700 Subject: [PATCH 2/3] ignore stubtest --- tests/stubtest_allowlists/py3_common.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/stubtest_allowlists/py3_common.txt b/tests/stubtest_allowlists/py3_common.txt index fe00bb286e66..8d1fdfead1ba 100644 --- a/tests/stubtest_allowlists/py3_common.txt +++ b/tests/stubtest_allowlists/py3_common.txt @@ -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 + _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 From 956fb6730e7e05b9e0f59ee4b87abf757333555b Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Mon, 31 Oct 2022 07:06:31 -0700 Subject: [PATCH 3/3] Update tests/stubtest_allowlists/py3_common.txt --- tests/stubtest_allowlists/py3_common.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/stubtest_allowlists/py3_common.txt b/tests/stubtest_allowlists/py3_common.txt index 8d1fdfead1ba..90b09baa1a0c 100644 --- a/tests/stubtest_allowlists/py3_common.txt +++ b/tests/stubtest_allowlists/py3_common.txt @@ -367,7 +367,7 @@ _ctypes.sizeof # Allowlist entries that cannot or should not be fixed # ========== -ctypes.Array.raw # exists but stubtest can't see it +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