diff --git a/stdlib/_ctypes.pyi b/stdlib/_ctypes.pyi index dcb870bc39d4..c97396df0a64 100644 --- a/stdlib/_ctypes.pyi +++ b/stdlib/_ctypes.pyi @@ -38,6 +38,10 @@ if sys.platform == "win32": FUNCFLAG_HRESULT: int FUNCFLAG_STDCALL: int + def FormatError(code: int = ...) -> str: ... + def get_last_error() -> int: ... + def set_last_error(value: int) -> int: ... + class _CDataMeta(type): # By default mypy complains about the following two methods, because strictly speaking cls # might not be a Type[_CT]. However this can never actually happen, because the only class that diff --git a/stdlib/ctypes/__init__.pyi b/stdlib/ctypes/__init__.pyi index c85d65c9f474..30f8416f09ca 100644 --- a/stdlib/ctypes/__init__.pyi +++ b/stdlib/ctypes/__init__.pyi @@ -16,6 +16,9 @@ from collections.abc import Callable, Sequence from typing import Any, ClassVar, Generic, TypeVar, overload from typing_extensions import TypeAlias +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, 9): from types import GenericAlias @@ -138,14 +141,9 @@ def create_unicode_buffer(init: int | str, size: int | None = None) -> Array[c_w if sys.platform == "win32": def DllCanUnloadNow() -> int: ... def DllGetClassObject(rclsid: Any, riid: Any, ppv: Any) -> int: ... # TODO not documented - def FormatError(code: int = ...) -> str: ... def GetLastError() -> int: ... def get_errno() -> int: ... - -if sys.platform == "win32": - def get_last_error() -> int: ... - def memmove(dst: _CVoidPLike, src: _CVoidConstPLike, count: int) -> int: ... def memset(dst: _CVoidPLike, c: int, count: int) -> int: ... def POINTER(type: type[_CT]) -> type[_Pointer[_CT]]: ... @@ -166,10 +164,6 @@ class _Pointer(Generic[_CT], _PointerLike, _CData): def pointer(__arg: _CT) -> _Pointer[_CT]: ... def resize(obj: _CData, size: int) -> None: ... def set_errno(value: int) -> int: ... - -if sys.platform == "win32": - def set_last_error(value: int) -> int: ... - def sizeof(obj_or_type: _CData | type[_CData]) -> int: ... def string_at(address: _CVoidConstPLike, size: int = -1) -> bytes: ... diff --git a/tests/stubtest_allowlists/win32.txt b/tests/stubtest_allowlists/win32.txt index 4d5ef5db4eb6..2404b2bce6df 100644 --- a/tests/stubtest_allowlists/win32.txt +++ b/tests/stubtest_allowlists/win32.txt @@ -23,11 +23,8 @@ ssl.SSLSocket.recvmsg ssl.SSLSocket.recvmsg_into ssl.SSLSocket.sendmsg winreg.HKEYType.handle -_ctypes.FormatError _ctypes.FreeLibrary _ctypes.LoadLibrary -_ctypes.get_last_error -_ctypes.set_last_error # ==========