Skip to content

Commit

Permalink
add missing ctypes things (python#13147)
Browse files Browse the repository at this point in the history
  • Loading branch information
tungol authored Nov 28, 2024
1 parent 5c7d51f commit 7a0f683
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
10 changes: 0 additions & 10 deletions stdlib/@tests/stubtest_allowlists/common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ xml.sax.expatreader
# TODO: Module members that exist at runtime, but are missing from stubs
# ==========
_thread.RLock
ctypes.ARRAY
ctypes.SetPointerType
ctypes.c_voidp
ctypes.util.test
multiprocessing.managers.Server.accepter
multiprocessing.managers.Server.create
multiprocessing.managers.Server.debug_info
Expand Down Expand Up @@ -101,12 +97,6 @@ multiprocessing.synchronize.Semaphore.get_value
tkinter.Misc.config
tkinter.font.Font.counter

_ctypes.PyObj_FromPtr
_ctypes.Py_DECREF
_ctypes.Py_INCREF
_ctypes.buffer_info
_ctypes.call_cdeclfunction
_ctypes.call_function

# ==========
# Modules that exist at runtime, but are deliberately missing from stubs
Expand Down
6 changes: 6 additions & 0 deletions stdlib/_ctypes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,9 @@ def get_errno() -> int: ...
def resize(obj: _CData | _CDataType, size: int, /) -> None: ...
def set_errno(value: int, /) -> int: ...
def sizeof(obj_or_type: _CData | _CDataType | type[_CData | _CDataType], /) -> int: ...
def PyObj_FromPtr(address: int, /) -> Any: ...
def Py_DECREF(o: _T, /) -> _T: ...
def Py_INCREF(o: _T, /) -> _T: ...
def buffer_info(o: _CData | _CDataType | type[_CData | _CDataType], /) -> tuple[str, int, tuple[int, ...]]: ...
def call_cdeclfunction(address: int, arguments: tuple[Any, ...], /) -> Any: ...
def call_function(address: int, arguments: tuple[Any, ...], /) -> Any: ...
10 changes: 9 additions & 1 deletion stdlib/ctypes/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ from _ctypes import (
)
from ctypes._endian import BigEndianStructure as BigEndianStructure, LittleEndianStructure as LittleEndianStructure
from typing import Any, ClassVar, Generic, TypeVar
from typing_extensions import Self, TypeAlias
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
Expand All @@ -39,6 +39,7 @@ if sys.version_info >= (3, 9):

_T = TypeVar("_T")
_DLLT = TypeVar("_DLLT", bound=CDLL)
_CT = TypeVar("_CT", bound=_CData)

DEFAULT_MODE: int

Expand Down Expand Up @@ -122,6 +123,11 @@ def create_string_buffer(init: int | bytes, size: int | None = None) -> Array[c_
c_buffer = create_string_buffer

def create_unicode_buffer(init: int | str, size: int | None = None) -> Array[c_wchar]: ...
@deprecated("Deprecated in Python 3.13; removal scheduled for Python 3.15")
def SetPointerType(
pointer: type[_Pointer[Any]], cls: Any # noqa: F811 # Redefinition of unused `pointer` from line 22
) -> None: ...
def ARRAY(typ: _CT, len: int) -> Array[_CT]: ... # Soft Deprecated, no plans to remove

if sys.platform == "win32":
def DllCanUnloadNow() -> int: ...
Expand Down Expand Up @@ -166,6 +172,8 @@ class c_void_p(_PointerLike, _SimpleCData[int | None]):
@classmethod
def from_param(cls, value: Any, /) -> Self | _CArgObject: ...

c_voidp = c_void_p # backwards compatibility (to a bug)

class c_wchar(_SimpleCData[str]): ...

c_int8 = c_byte
Expand Down
2 changes: 2 additions & 0 deletions stdlib/ctypes/util.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ def find_library(name: str) -> str | None: ...

if sys.platform == "win32":
def find_msvcrt() -> str | None: ...

def test() -> None: ...

0 comments on commit 7a0f683

Please sign in to comment.