Skip to content

Commit 7a0f683

Browse files
authored
add missing ctypes things (#13147)
1 parent 5c7d51f commit 7a0f683

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

stdlib/@tests/stubtest_allowlists/common.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ xml.sax.expatreader
6666
# TODO: Module members that exist at runtime, but are missing from stubs
6767
# ==========
6868
_thread.RLock
69-
ctypes.ARRAY
70-
ctypes.SetPointerType
71-
ctypes.c_voidp
72-
ctypes.util.test
7369
multiprocessing.managers.Server.accepter
7470
multiprocessing.managers.Server.create
7571
multiprocessing.managers.Server.debug_info
@@ -101,12 +97,6 @@ multiprocessing.synchronize.Semaphore.get_value
10197
tkinter.Misc.config
10298
tkinter.font.Font.counter
10399

104-
_ctypes.PyObj_FromPtr
105-
_ctypes.Py_DECREF
106-
_ctypes.Py_INCREF
107-
_ctypes.buffer_info
108-
_ctypes.call_cdeclfunction
109-
_ctypes.call_function
110100

111101
# ==========
112102
# Modules that exist at runtime, but are deliberately missing from stubs

stdlib/_ctypes.pyi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,3 +326,9 @@ def get_errno() -> int: ...
326326
def resize(obj: _CData | _CDataType, size: int, /) -> None: ...
327327
def set_errno(value: int, /) -> int: ...
328328
def sizeof(obj_or_type: _CData | _CDataType | type[_CData | _CDataType], /) -> int: ...
329+
def PyObj_FromPtr(address: int, /) -> Any: ...
330+
def Py_DECREF(o: _T, /) -> _T: ...
331+
def Py_INCREF(o: _T, /) -> _T: ...
332+
def buffer_info(o: _CData | _CDataType | type[_CData | _CDataType], /) -> tuple[str, int, tuple[int, ...]]: ...
333+
def call_cdeclfunction(address: int, arguments: tuple[Any, ...], /) -> Any: ...
334+
def call_function(address: int, arguments: tuple[Any, ...], /) -> Any: ...

stdlib/ctypes/__init__.pyi

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ from _ctypes import (
2626
)
2727
from ctypes._endian import BigEndianStructure as BigEndianStructure, LittleEndianStructure as LittleEndianStructure
2828
from typing import Any, ClassVar, Generic, TypeVar
29-
from typing_extensions import Self, TypeAlias
29+
from typing_extensions import Self, TypeAlias, deprecated
3030

3131
if sys.platform == "win32":
3232
from _ctypes import FormatError as FormatError, get_last_error as get_last_error, set_last_error as set_last_error
@@ -39,6 +39,7 @@ if sys.version_info >= (3, 9):
3939

4040
_T = TypeVar("_T")
4141
_DLLT = TypeVar("_DLLT", bound=CDLL)
42+
_CT = TypeVar("_CT", bound=_CData)
4243

4344
DEFAULT_MODE: int
4445

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

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

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

175+
c_voidp = c_void_p # backwards compatibility (to a bug)
176+
169177
class c_wchar(_SimpleCData[str]): ...
170178

171179
c_int8 = c_byte

stdlib/ctypes/util.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ def find_library(name: str) -> str | None: ...
44

55
if sys.platform == "win32":
66
def find_msvcrt() -> str | None: ...
7+
8+
def test() -> None: ...

0 commit comments

Comments
 (0)