Skip to content

Commit bbeec7c

Browse files
authored
Move some Windows-specific things from ctypes/__init__.pyi to _ctypes.pyi (#10128)
- `FormatError` - `get_last_error` - `set_last_error`
1 parent d208d5a commit bbeec7c

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

stdlib/_ctypes.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ if sys.platform == "win32":
3838
FUNCFLAG_HRESULT: int
3939
FUNCFLAG_STDCALL: int
4040

41+
def FormatError(code: int = ...) -> str: ...
42+
def get_last_error() -> int: ...
43+
def set_last_error(value: int) -> int: ...
44+
4145
class _CDataMeta(type):
4246
# By default mypy complains about the following two methods, because strictly speaking cls
4347
# might not be a Type[_CT]. However this can never actually happen, because the only class that

stdlib/ctypes/__init__.pyi

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ from collections.abc import Callable, Sequence
1616
from typing import Any, ClassVar, Generic, TypeVar, overload
1717
from typing_extensions import TypeAlias
1818

19+
if sys.platform == "win32":
20+
from _ctypes import FormatError as FormatError, get_last_error as get_last_error, set_last_error as set_last_error
21+
1922
if sys.version_info >= (3, 9):
2023
from types import GenericAlias
2124

@@ -138,14 +141,9 @@ def create_unicode_buffer(init: int | str, size: int | None = None) -> Array[c_w
138141
if sys.platform == "win32":
139142
def DllCanUnloadNow() -> int: ...
140143
def DllGetClassObject(rclsid: Any, riid: Any, ppv: Any) -> int: ... # TODO not documented
141-
def FormatError(code: int = ...) -> str: ...
142144
def GetLastError() -> int: ...
143145

144146
def get_errno() -> int: ...
145-
146-
if sys.platform == "win32":
147-
def get_last_error() -> int: ...
148-
149147
def memmove(dst: _CVoidPLike, src: _CVoidConstPLike, count: int) -> int: ...
150148
def memset(dst: _CVoidPLike, c: int, count: int) -> int: ...
151149
def POINTER(type: type[_CT]) -> type[_Pointer[_CT]]: ...
@@ -166,10 +164,6 @@ class _Pointer(Generic[_CT], _PointerLike, _CData):
166164
def pointer(__arg: _CT) -> _Pointer[_CT]: ...
167165
def resize(obj: _CData, size: int) -> None: ...
168166
def set_errno(value: int) -> int: ...
169-
170-
if sys.platform == "win32":
171-
def set_last_error(value: int) -> int: ...
172-
173167
def sizeof(obj_or_type: _CData | type[_CData]) -> int: ...
174168
def string_at(address: _CVoidConstPLike, size: int = -1) -> bytes: ...
175169

tests/stubtest_allowlists/win32.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,8 @@ ssl.SSLSocket.recvmsg
2323
ssl.SSLSocket.recvmsg_into
2424
ssl.SSLSocket.sendmsg
2525
winreg.HKEYType.handle
26-
_ctypes.FormatError
2726
_ctypes.FreeLibrary
2827
_ctypes.LoadLibrary
29-
_ctypes.get_last_error
30-
_ctypes.set_last_error
3128

3229

3330
# ==========

0 commit comments

Comments
 (0)