From 4ea1f958ce268e1d312a0d5494ba365164862c9f Mon Sep 17 00:00:00 2001 From: Semyon Moroz Date: Mon, 26 May 2025 01:13:36 +0000 Subject: [PATCH] Bump `ctypes` to 3.14 (#14137) --- .../stubtest_allowlists/darwin-py314.txt | 3 --- .../stubtest_allowlists/linux-py314.txt | 3 --- stdlib/@tests/stubtest_allowlists/py314.txt | 11 ---------- .../stubtest_allowlists/win32-py314.txt | 3 --- stdlib/_ctypes.pyi | 2 ++ stdlib/ctypes/__init__.pyi | 20 +++++++++++++------ stdlib/ctypes/util.pyi | 3 +++ stdlib/ctypes/wintypes.pyi | 9 +++++++++ 8 files changed, 28 insertions(+), 26 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/darwin-py314.txt b/stdlib/@tests/stubtest_allowlists/darwin-py314.txt index ee8fd760e..6db5ea944 100644 --- a/stdlib/@tests/stubtest_allowlists/darwin-py314.txt +++ b/stdlib/@tests/stubtest_allowlists/darwin-py314.txt @@ -3,9 +3,6 @@ # ==================================================================== asyncio.tools -ctypes.c_double_complex._type_ -ctypes.c_float_complex._type_ -ctypes.c_longdouble_complex._type_ # ======= diff --git a/stdlib/@tests/stubtest_allowlists/linux-py314.txt b/stdlib/@tests/stubtest_allowlists/linux-py314.txt index 6673766ea..d2f10ffdc 100644 --- a/stdlib/@tests/stubtest_allowlists/linux-py314.txt +++ b/stdlib/@tests/stubtest_allowlists/linux-py314.txt @@ -3,6 +3,3 @@ # ==================================================================== asyncio.tools -ctypes.c_double_complex._type_ -ctypes.c_float_complex._type_ -ctypes.c_longdouble_complex._type_ diff --git a/stdlib/@tests/stubtest_allowlists/py314.txt b/stdlib/@tests/stubtest_allowlists/py314.txt index b5a5418a6..223ee2285 100644 --- a/stdlib/@tests/stubtest_allowlists/py314.txt +++ b/stdlib/@tests/stubtest_allowlists/py314.txt @@ -16,17 +16,6 @@ compression.gzip.GzipFile.readinto1 compression.gzip.GzipFile.readinto1 compression.gzip.compress compression.zstd -ctypes.memoryview_at -ctypes.py_object.__class_getitem__ -ctypes.util.dllist -ctypes.wintypes.HCONV -ctypes.wintypes.HCONVLIST -ctypes.wintypes.HCURSOR -ctypes.wintypes.HDDEDATA -ctypes.wintypes.HDROP -ctypes.wintypes.HFILE -ctypes.wintypes.HRESULT -ctypes.wintypes.HSZ fractions.Fraction.__pow__ fractions.Fraction.__rpow__ gzip.GzipFile.readinto diff --git a/stdlib/@tests/stubtest_allowlists/win32-py314.txt b/stdlib/@tests/stubtest_allowlists/win32-py314.txt index 5f1eee1b3..055f91f97 100644 --- a/stdlib/@tests/stubtest_allowlists/win32-py314.txt +++ b/stdlib/@tests/stubtest_allowlists/win32-py314.txt @@ -4,9 +4,6 @@ _winapi.COPY_FILE_DIRECTORY compression.zlib.ZLIBNG_VERSION -ctypes.c_double_complex -ctypes.c_float_complex -ctypes.c_longdouble_complex encodings.win32_code_page_search_function nt.readinto pathlib.Path.group diff --git a/stdlib/_ctypes.pyi b/stdlib/_ctypes.pyi index 944685646..35c77619d 100644 --- a/stdlib/_ctypes.pyi +++ b/stdlib/_ctypes.pyi @@ -75,6 +75,8 @@ class _CData: _objects: Mapping[Any, int] | None def __buffer__(self, flags: int, /) -> memoryview: ... def __ctypes_from_outparam__(self, /) -> Self: ... + if sys.version_info >= (3, 14): + __pointer_type__: type # this is a union of all the subclasses of _CData, which is useful because of # the methods that are present on each of those subclasses which are not present diff --git a/stdlib/ctypes/__init__.pyi b/stdlib/ctypes/__init__.pyi index 68b75b86d..0b14bd856 100644 --- a/stdlib/ctypes/__init__.pyi +++ b/stdlib/ctypes/__init__.pyi @@ -31,6 +31,9 @@ from typing_extensions import Self, TypeAlias, deprecated if sys.platform == "win32": from _ctypes import FormatError as FormatError, get_last_error as get_last_error, set_last_error as set_last_error + if sys.version_info >= (3, 14): + from _ctypes import COMError as COMError + if sys.version_info >= (3, 11): from ctypes._endian import BigEndianUnion as BigEndianUnion, LittleEndianUnion as LittleEndianUnion @@ -197,8 +200,13 @@ if sys.platform == "win32": def wstring_at(ptr: _CVoidConstPLike, size: int = -1) -> str: ... +if sys.version_info >= (3, 14): + def memoryview_at(ptr: _CVoidConstPLike, size: int, readonly: bool = False) -> memoryview: ... + class py_object(_CanCastTo, _SimpleCData[_T]): _type_: ClassVar[Literal["O"]] + if sys.version_info >= (3, 14): + def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... class c_bool(_SimpleCData[bool]): _type_: ClassVar[Literal["?"]] @@ -270,15 +278,15 @@ class c_double(_SimpleCData[float]): class c_longdouble(_SimpleCData[float]): # can be an alias for c_double _type_: ClassVar[Literal["d", "g"]] -if sys.version_info >= (3, 14): - class c_float_complex(_SimpleCData[complex]): - _type_: ClassVar[Literal["E"]] - +if sys.version_info >= (3, 14) and sys.platform != "win32": class c_double_complex(_SimpleCData[complex]): - _type_: ClassVar[Literal["C"]] + _type_: ClassVar[Literal["D"]] + + class c_float_complex(_SimpleCData[complex]): + _type_: ClassVar[Literal["F"]] class c_longdouble_complex(_SimpleCData[complex]): - _type_: ClassVar[Literal["F"]] + _type_: ClassVar[Literal["G"]] class c_char(_SimpleCData[bytes]): _type_: ClassVar[Literal["c"]] diff --git a/stdlib/ctypes/util.pyi b/stdlib/ctypes/util.pyi index 316f7a2b3..4f18c1d8d 100644 --- a/stdlib/ctypes/util.pyi +++ b/stdlib/ctypes/util.pyi @@ -5,4 +5,7 @@ def find_library(name: str) -> str | None: ... if sys.platform == "win32": def find_msvcrt() -> str | None: ... +if sys.version_info >= (3, 14): + def dllist() -> list[str]: ... + def test() -> None: ... diff --git a/stdlib/ctypes/wintypes.pyi b/stdlib/ctypes/wintypes.pyi index 63f117787..e9ed0df24 100644 --- a/stdlib/ctypes/wintypes.pyi +++ b/stdlib/ctypes/wintypes.pyi @@ -83,6 +83,15 @@ HACCEL = HANDLE HBITMAP = HANDLE HBRUSH = HANDLE HCOLORSPACE = HANDLE +if sys.version_info >= (3, 14): + HCONV = HANDLE + HCONVLIST = HANDLE + HCURSOR = HANDLE + HDDEDATA = HANDLE + HDROP = HANDLE + HFILE = INT + HRESULT = LONG + HSZ = HANDLE HDC = HANDLE HDESK = HANDLE HDWP = HANDLE