8000 Move some pointer-related definitions from `ctypes/__init__.pyi` to `… · python/typeshed@01b09d4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 01b09d4

Browse files
authored
Move some pointer-related definitions from ctypes/__init__.pyi to _ctypes.pyi (#10133)
1 parent 06878a9 commit 01b09d4

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

stdlib/_ctypes.pyi

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import sys
22
from _typeshed import ReadableBuffer, WriteableBuffer
33
from abc import abstractmethod
44
from collections.abc import Iterable, Iterator, Mapping, Sequence
5-
from ctypes import CDLL, _CArgObject, _PointerLike
5+
from ctypes import CDLL, _CArgObject
66
from typing import Any, Generic, TypeVar, overload
77
from typing_extensions import Self, TypeAlias
88

@@ -70,6 +70,25 @@ class _SimpleCData(Generic[_T], _CData):
7070
# but we can't use overloads without creating many, many mypy false-positive errors
7171
def __init__(self, value: _T = ...) -> None: ... # pyright: ignore[reportInvalidTypeVarUse]
7272

73+
class _CanCastTo(_CData): ...
74+
class _PointerLike(_CanCastTo): ...
75+
76+
class _Pointer(Generic[_CT], _PointerLike, _CData):
77+
_type_: type[_CT]
78+
contents: _CT
79+
@overload
80+
def __init__(self) -> None: ...
81+
@overload
82+
def __init__(self, arg: _CT) -> None: ...
83+
@overload
84+
def __getitem__(self, __key: int) -> Any: ...
85+
@overload
86+
def __getitem__(self, __key: slice) -> list[Any]: ...
87+
def __setitem__(self, __key: int, __value: Any) -> None: ...
88+
89+
def POINTER(type: type[_CT]) -> type[_Pointer[_CT]]: ...
90+
def pointer(__arg: _CT) -> _Pointer[_CT]: ...
91+
7392
class _CField:
7493
offset: int
7594
size: int

stdlib/ctypes/__init__.pyi

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
import sys
22
from _ctypes import (
3+
POINTER as POINTER,
34
RTLD_GLOBAL as RTLD_GLOBAL,
45
RTLD_LOCAL as RTLD_LOCAL,
56
ArgumentError as ArgumentError,
67
Array as Array,
78
Structure as Structure,
89
Union as Union,
10+
_CanCastTo as _CanCastTo,
911
_CData as _CData,
1012
_CDataMeta as _CDataMeta,
1113
_CField as _CField,
14+
_Pointer as _Pointer,
15+
_PointerLike as _PointerLike,
1216
_SimpleCData as _SimpleCData,
1317
_StructUnionBase as _StructUnionBase,
1418
_StructUnionMeta as _StructUnionMeta,
1519
addressof as addressof,
1620
alignment as alignment,
1721
get_errno as get_errno,
22+
pointer as pointer,
1823
resize as resize,
1924
set_errno as set_errno,
2025
sizeof as sizeof,
@@ -31,7 +36,6 @@ if sys.version_info >= (3, 9):
3136

3237
_T = TypeVar("_T")
3338
_DLLT = TypeVar("_DLLT", bound=CDLL)
34-
_CT = TypeVar("_CT", bound=_CData)
3539

3640
DEFAULT_MODE: int
3741

@@ -85,9 +89,6 @@ if sys.platform == "win32":
8589
pydll: LibraryLoader[PyDLL]
8690
pythonapi: PyDLL
8791

88-
class _CanCastTo(_CData): ...
89-
class _PointerLike(_CanCastTo): ...
90-
9192
_ECT: TypeAlias = Callable[[type[_CData] | None, _FuncPointer, tuple[_CData, ...]], _CData]
9293
_PF: TypeAlias = tuple[int] | tuple[int, str] | tuple[int, str, Any]
9394

@@ -148,22 +149,6 @@ if sys.platform == "win32":
148149

149150
def memmove(dst: _CVoidPLike, src: _CVoidConstPLike, count: int) -> int: ...
150151
def memset(dst: _CVoidPLike, c: int, count: int) -> int: ...
151-
def POINTER(type: type[_CT]) -> type[_Pointer[_CT]]: ...
152-
153-
class _Pointer(Generic[_CT], _PointerLike, _CData):
154-
_type_: type[_CT]
155-
contents: _CT
156-
@overload
157-
def __init__(self) -> None: ...
158-
@overload
159-
def __init__(self, arg: _CT) -> None: ...
160-
@overload
161-
def __getitem__(self, __key: int) -> Any: ...
162-
@overload
163-
def __getitem__(self, __key: slice) -> list[Any]: ...
164-
def __setitem__(self, __key: int, __value: Any) -> None: ...
165-
166-
def pointer(__arg: _CT) -> _Pointer[_CT]: ...
167152
def string_at(address: _CVoidConstPLike, size: int = -1) -> bytes: ...
168153

169154
if sys.platform == "win32":

tests/stubtest_allowlists/py3_common.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,15 +335,13 @@ wave.Wave_read.initfp
335335
wave.Wave_write.initfp
336336

337337
_ctypes.CFuncPtr
338-
_ctypes.POINTER
339338
_ctypes.PyObj_FromPtr
340339
_ctypes.Py_DECREF
341340
_ctypes.Py_INCREF
342341
_ctypes.buffer_info
343342
_ctypes.byref
344343
_ctypes.call_cdeclfunction
345344
_ctypes.call_function
346-
_ctypes.pointer
347345

348346
# ==========
349347
# Allowlist entries that cannot or should not be fixed

0 commit comments

Comments
 (0)
0