Skip to content

move some stuffs related to Windows from ctypes/__init__.pyi to _ctypes.pyi, as at runtime. #10128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions stdlib/_ctypes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 3 additions & 9 deletions stdlib/ctypes/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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]]: ...
Expand All @@ -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: ...

Expand Down
3 changes: 0 additions & 3 deletions tests/stubtest_allowlists/win32.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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


# ==========
Expand Down