Skip to content

Commit 47093e2

Browse files
sobolevnmingyu.park
authored andcommitted
Update _ctypes to 3.14 (python#14043)
1 parent 7176c7e commit 47093e2

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

stdlib/@tests/stubtest_allowlists/py314.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
_asyncio.all_tasks
66
_asyncio.future_add_to_awaited_by
77
_asyncio.future_discard_from_awaited_by
8-
_ctypes.POINTER
9-
_ctypes.byref
10-
_ctypes.pointer
118
_heapq.heapify_max
129
_heapq.heappop_max
1310
_heapq.heappush_max
@@ -54,10 +51,7 @@ compression.gzip.GzipFile.readinto1
5451
compression.gzip.GzipFile.readinto1
5552
compression.gzip.compress
5653
compression.zstd
57-
ctypes.POINTER
58-
ctypes.byref
5954
ctypes.memoryview_at
60-
ctypes.pointer
6155
ctypes.py_object.__class_getitem__
6256
ctypes.util.dllist
6357
ctypes.wintypes.HCONV

stdlib/_ctypes.pyi

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,23 @@ class _Pointer(_PointerLike, _CData, Generic[_CT], metaclass=_PyCPointerType):
131131
def __getitem__(self, key: slice, /) -> list[Any]: ...
132132
def __setitem__(self, key: int, value: Any, /) -> None: ...
133133

134-
@overload
135-
def POINTER(type: None, /) -> type[c_void_p]: ...
136-
@overload
137-
def POINTER(type: type[_CT], /) -> type[_Pointer[_CT]]: ...
138-
def pointer(obj: _CT, /) -> _Pointer[_CT]: ...
134+
if sys.version_info < (3, 14):
135+
@overload
136+
def POINTER(type: None, /) -> type[c_void_p]: ...
137+
@overload
138+
def POINTER(type: type[_CT], /) -> type[_Pointer[_CT]]: ...
139+
def pointer(obj: _CT, /) -> _Pointer[_CT]: ...
139140

140141
# This class is not exposed. It calls itself _ctypes.CArgObject.
141142
@final
142143
@type_check_only
143144
class _CArgObject: ...
144145

145-
def byref(obj: _CData | _CDataType, offset: int = ...) -> _CArgObject: ...
146+
if sys.version_info >= (3, 14):
147+
def byref(obj: _CData | _CDataType, offset: int = 0, /) -> _CArgObject: ...
148+
149+
else:
150+
def byref(obj: _CData | _CDataType, offset: int = 0) -> _CArgObject: ...
146151

147152
_ECT: TypeAlias = Callable[[_CData | _CDataType | None, CFuncPtr, tuple[_CData | _CDataType, ...]], _CDataType]
148153
_PF: TypeAlias = tuple[int] | tuple[int, str | None] | tuple[int, str | None, Any]

stdlib/ctypes/__init__.pyi

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import sys
22
from _ctypes import (
3-
POINTER as POINTER,
43
RTLD_GLOBAL as RTLD_GLOBAL,
54
RTLD_LOCAL as RTLD_LOCAL,
65
Array as Array,
@@ -19,15 +18,14 @@ from _ctypes import (
1918
alignment as alignment,
2019
byref as byref,
2120
get_errno as get_errno,
22-
pointer as pointer,
2321
resize as resize,
2422
set_errno as set_errno,
2523
sizeof as sizeof,
2624
)
2725
from _typeshed import StrPath
2826
from ctypes._endian import BigEndianStructure as BigEndianStructure, LittleEndianStructure as LittleEndianStructure
2927
from types import GenericAlias
30-
from typing import Any, ClassVar, Generic, Literal, TypeVar, type_check_only
28+
from typing import Any, ClassVar, Generic, Literal, TypeVar, overload, type_check_only
3129
from typing_extensions import Self, TypeAlias, deprecated
3230

3331
if sys.platform == "win32":
@@ -36,9 +34,22 @@ if sys.platform == "win32":
3634
if sys.version_info >= (3, 11):
3735
from ctypes._endian import BigEndianUnion as BigEndianUnion, LittleEndianUnion as LittleEndianUnion
3836

37+
_CT = TypeVar("_CT", bound=_CData)
3938
_T = TypeVar("_T", default=Any)
4039
_DLLT = TypeVar("_DLLT", bound=CDLL)
41-
_CT = TypeVar("_CT", bound=_CData)
40+
41+
if sys.version_info >= (3, 14):
42+
@overload
43+
@deprecated("ctypes.POINTER with string")
44+
def POINTER(obj: str) -> type[Any]: ...
45+
@overload
46+
def POINTER(obj: None) -> type[c_void_p]: ...
47+
@overload
48+
def POINTER(obj: type[_CT]) -> type[_Pointer[_CT]]: ...
49+
def pointer(obj: _CT) -> _Pointer[_CT]: ...
50+
51+
else:
52+
from _ctypes import POINTER as POINTER, pointer as pointer
4253

4354
DEFAULT_MODE: int
4455

@@ -148,7 +159,7 @@ c_buffer = create_string_buffer
148159

149160
def create_unicode_buffer(init: int | str, size: int | None = None) -> Array[c_wchar]: ...
150161
@deprecated("Deprecated in Python 3.13; removal scheduled for Python 3.15")
151-
def SetPointerType(pointer: type[_Pointer[Any]], cls: Any) -> None: ... # noqa: F811
162+
def SetPointerType(pointer: type[_Pointer[Any]], cls: Any) -> None: ...
152163
def ARRAY(typ: _CT, len: int) -> Array[_CT]: ... # Soft Deprecated, no plans to remove
153164

154165
if sys.platform == "win32":

0 commit comments

Comments
 (0)