Skip to content
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
9 changes: 9 additions & 0 deletions stdlib/_ctypes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,12 @@ class Array(Generic[_CT], _CData):
def __len__(self) -> int: ...
if sys.version_info >= (3, 9):
def __class_getitem__(cls, item: Any) -> GenericAlias: ...

class ArgumentError(Exception): ...

def addressof(obj: _CData) -> int: ...
def alignment(obj_or_type: _CData | type[_CData]) -> int: ...
def get_errno() -> int: ...
def resize(obj: _CData, size: int) -> None: ...
def set_errno(value: int) -> int: ...
def sizeof(obj_or_type: _CData | type[_CData]) -> int: ...
15 changes: 7 additions & 8 deletions stdlib/ctypes/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import sys
from _ctypes import (
RTLD_GLOBAL as RTLD_GLOBAL,
RTLD_LOCAL as RTLD_LOCAL,
ArgumentError as ArgumentError,
Array as Array,
Structure as Structure,
Union as Union,
Expand All @@ -11,6 +12,12 @@ from _ctypes import (
_SimpleCData as _SimpleCData,
_StructUnionBase as _StructUnionBase,
_StructUnionMeta as _StructUnionMeta,
addressof as addressof,
alignment as alignment,
get_errno as get_errno,
resize as resize,
set_errno as set_errno,
sizeof as sizeof,
)
from collections.abc import Callable, Sequence
from typing import Any, ClassVar, Generic, TypeVar, overload
Expand Down Expand Up @@ -101,8 +108,6 @@ class _FuncPointer(_PointerLike, _CData):
class _NamedFuncPointer(_FuncPointer):
__name__: str

class ArgumentError(Exception): ...

def CFUNCTYPE(
restype: type[_CData] | None, *argtypes: type[_CData], use_errno: bool = ..., use_last_error: bool = ...
) -> type[_FuncPointer]: ...
Expand All @@ -125,8 +130,6 @@ _CVoidPLike: TypeAlias = _PointerLike | Array[Any] | _CArgObject | int
# when memmove(buf, b'foo', 4) was intended.
_CVoidConstPLike: TypeAlias = _CVoidPLike | bytes

def addressof(obj: _CData) -> int: ...
def alignment(obj_or_type: _CData | type[_CData]) -> int: ...
def byref(obj: _CData, offset: int = ...) -> _CArgObject: ...

_CastT = TypeVar("_CastT", bound=_CanCastTo)
Expand All @@ -143,7 +146,6 @@ if sys.platform == "win32":
def DllGetClassObject(rclsid: Any, riid: Any, ppv: Any) -> int: ... # TODO not documented
def GetLastError() -> int: ...

def get_errno() -> 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 @@ -162,9 +164,6 @@ class _Pointer(Generic[_CT], _PointerLike, _CData):
def __setitem__(self, __key: int, __value: Any) -> None: ...

def pointer(__arg: _CT) -> _Pointer[_CT]: ...
def resize(obj: _CData, size: int) -> None: ...
def set_errno(value: int) -> int: ...
def sizeof(obj_or_type: _CData | type[_CData]) -> int: ...
def string_at(address: _CVoidConstPLike, size: int = -1) -> bytes: ...

if sys.platform == "win32":
Expand Down
6 changes: 0 additions & 6 deletions tests/stubtest_allowlists/py3_common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -339,17 +339,11 @@ _ctypes.POINTER
_ctypes.PyObj_FromPtr
_ctypes.Py_DECREF
_ctypes.Py_INCREF
_ctypes.addressof
_ctypes.alignment
_ctypes.buffer_info
_ctypes.byref
_ctypes.call_cdeclfunction
_ctypes.call_function
_ctypes.get_errno
_ctypes.pointer
_ctypes.resize
_ctypes.set_errno
_ctypes.sizeof

# ==========
# Allowlist entries that cannot or should not be fixed
Expand Down