Skip to content

Commit 87fc724

Browse files
authored
ctypes: pointer is a function, not a class (#8446)
1 parent ea7bbbd commit 87fc724

File tree

3 files changed

+59
-59
lines changed

3 files changed

+59
-59
lines changed

stdlib/ctypes/__init__.pyi

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class _FuncPointer(_PointerLike, _CData):
100100
@overload
101101
def __init__(self, func_spec: tuple[str | int, CDLL], paramflags: tuple[_PF, ...] = ...) -> None: ...
102102
@overload
103-
def __init__(self, vtlb_index: int, name: str, paramflags: tuple[_PF, ...] = ..., iid: pointer[c_int] = ...) -> None: ...
103+
def __init__(self, vtlb_index: int, name: str, paramflags: tuple[_PF, ...] = ..., iid: _Pointer[c_int] = ...) -> None: ...
104104
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
105105

106106
class _NamedFuncPointer(_FuncPointer):
@@ -156,14 +156,14 @@ if sys.platform == "win32":
156156

157157
def memmove(dst: _CVoidPLike, src: _CVoidConstPLike, count: int) -> int: ...
158158
def memset(dst: _CVoidPLike, c: int, count: int) -> int: ...
159-
def POINTER(type: type[_CT]) -> type[pointer[_CT]]: ...
159+
def POINTER(type: type[_CT]) -> type[_Pointer[_CT]]: ...
160160

161-
# The real ctypes.pointer is a function, not a class. The stub version of pointer behaves like
162-
# ctypes._Pointer in that it is the base class for all pointer types. Unlike the real _Pointer,
163-
# it can be instantiated directly (to mimic the behavior of the real pointer function).
164-
class pointer(Generic[_CT], _PointerLike, _CData):
161+
class _Pointer(Generic[_CT], _PointerLike, _CData):
165162
_type_: type[_CT]
166163
contents: _CT
164+
@overload
165+
def __init__(self) -> None: ...
166+
@overload
167167
def __init__(self, arg: _CT) -> None: ...
168168
@overload
169169
def __getitem__(self, __i: int) -> _CT: ...
@@ -174,6 +174,7 @@ class pointer(Generic[_CT], _PointerLike, _CData):
174174
@overload
175175
def __setitem__(self, __s: slice, __o: Iterable[_CT]) -> None: ...
176176

177+
def pointer(__arg: _CT) -> _Pointer[_CT]: ...
177178
def resize(obj: _CData, size: int) -> None: ...
178179
def set_errno(value: int) -> int: ...
179180

stdlib/ctypes/wintypes.pyi

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from ctypes import (
22
Array,
33
Structure,
4+
_Pointer,
45
_SimpleCData,
56
c_byte,
67
c_char,
@@ -18,7 +19,6 @@ from ctypes import (
1819
c_void_p,
1920
c_wchar,
2021
c_wchar_p,
21-
pointer,
2222
)
2323
from typing_extensions import TypeAlias
2424

@@ -181,55 +181,55 @@ class WIN32_FIND_DATAW(Structure):
181181
cFileName: Array[WCHAR]
182182
cAlternateFileName: Array[WCHAR]
183183

184-
# These pointer type definitions use pointer[...] instead of POINTER(...), to allow them
184+
# These pointer type definitions use _Pointer[...] instead of POINTER(...), to allow them
185185
# to be used in type annotations.
186-
PBOOL: TypeAlias = pointer[BOOL]
187-
LPBOOL: TypeAlias = pointer[BOOL]
188-
PBOOLEAN: TypeAlias = pointer[BOOLEAN]
189-
PBYTE: TypeAlias = pointer[BYTE]
190-
LPBYTE: TypeAlias = pointer[BYTE]
191-
PCHAR: TypeAlias = pointer[CHAR]
192-
LPCOLORREF: TypeAlias = pointer[COLORREF]
193-
PDWORD: TypeAlias = pointer[DWORD]
194-
LPDWORD: TypeAlias = pointer[DWORD]
195-
PFILETIME: TypeAlias = pointer[FILETIME]
196-
LPFILETIME: TypeAlias = pointer[FILETIME]
197-
PFLOAT: TypeAlias = pointer[FLOAT]
198-
PHANDLE: TypeAlias = pointer[HANDLE]
199-
LPHANDLE: TypeAlias = pointer[HANDLE]
200-
PHKEY: TypeAlias = pointer[HKEY]
201-
LPHKL: TypeAlias = pointer[HKL]
202-
PINT: TypeAlias = pointer[INT]
203-
LPINT: TypeAlias = pointer[INT]
204-
PLARGE_INTEGER: TypeAlias = pointer[LARGE_INTEGER]
205-
PLCID: TypeAlias = pointer[LCID]
206-
PLONG: TypeAlias = pointer[LONG]
207-
LPLONG: TypeAlias = pointer[LONG]
208-
PMSG: TypeAlias = pointer[MSG]
209-
LPMSG: TypeAlias = pointer[MSG]
210-
PPOINT: TypeAlias = pointer[POINT]
211-
LPPOINT: TypeAlias = pointer[POINT]
212-
PPOINTL: TypeAlias = pointer[POINTL]
213-
PRECT: TypeAlias = pointer[RECT]
214-
LPRECT: TypeAlias = pointer[RECT]
215-
PRECTL: TypeAlias = pointer[RECTL]
216-
LPRECTL: TypeAlias = pointer[RECTL]
217-
LPSC_HANDLE: TypeAlias = pointer[SC_HANDLE]
218-
PSHORT: TypeAlias = pointer[SHORT]
219-
PSIZE: TypeAlias = pointer[SIZE]
220-
LPSIZE: TypeAlias = pointer[SIZE]
221-
PSIZEL: TypeAlias = pointer[SIZEL]
222-
LPSIZEL: TypeAlias = pointer[SIZEL]
223-
PSMALL_RECT: TypeAlias = pointer[SMALL_RECT]
224-
PUINT: TypeAlias = pointer[UINT]
225-
LPUINT: TypeAlias = pointer[UINT]
226-
PULARGE_INTEGER: TypeAlias = pointer[ULARGE_INTEGER]
227-
PULONG: TypeAlias = pointer[ULONG]
228-
PUSHORT: TypeAlias = pointer[USHORT]
229-
PWCHAR: TypeAlias = pointer[WCHAR]
230-
PWIN32_FIND_DATAA: TypeAlias = pointer[WIN32_FIND_DATAA]
231-
LPWIN32_FIND_DATAA: TypeAlias = pointer[WIN32_FIND_DATAA]
232-
PWIN32_FIND_DATAW: TypeAlias = pointer[WIN32_FIND_DATAW]
233-
LPWIN32_FIND_DATAW: TypeAlias = pointer[WIN32_FIND_DATAW]
234-
PWORD: TypeAlias = pointer[WORD]
235-
LPWORD: TypeAlias = pointer[WORD]
186+
PBOOL: TypeAlias = _Pointer[BOOL]
187+
LPBOOL: TypeAlias = _Pointer[BOOL]
188+
PBOOLEAN: TypeAlias = _Pointer[BOOLEAN]
189+
PBYTE: TypeAlias = _Pointer[BYTE]
190+
LPBYTE: TypeAlias = _Pointer[BYTE]
191+
PCHAR: TypeAlias = _Pointer[CHAR]
192+
LPCOLORREF: TypeAlias = _Pointer[COLORREF]
193+
PDWORD: TypeAlias = _Pointer[DWORD]
194+
LPDWORD: TypeAlias = _Pointer[DWORD]
195+
PFILETIME: TypeAlias = _Pointer[FILETIME]
196+
LPFILETIME: TypeAlias = _Pointer[FILETIME]
197+
PFLOAT: TypeAlias = _Pointer[FLOAT]
198+
PHANDLE: TypeAlias = _Pointer[HANDLE]
199+
LPHANDLE: TypeAlias = _Pointer[HANDLE]
200+
PHKEY: TypeAlias = _Pointer[HKEY]
201+
LPHKL: TypeAlias = _Pointer[HKL]
202+
PINT: TypeAlias = _Pointer[INT]
203+
LPINT: TypeAlias = _Pointer[INT]
204+
PLARGE_INTEGER: TypeAlias = _Pointer[LARGE_INTEGER]
205+
PLCID: TypeAlias = _Pointer[LCID]
206+
PLONG: TypeAlias = _Pointer[LONG]
207+
LPLONG: TypeAlias = _Pointer[LONG]
208+
PMSG: TypeAlias = _Pointer[MSG]
209+
LPMSG: TypeAlias = _Pointer[MSG]
210+
PPOINT: TypeAlias = _Pointer[POINT]
211+
LPPOINT: TypeAlias = _Pointer[POINT]
212+
PPOINTL: TypeAlias = _Pointer[POINTL]
213+
PRECT: TypeAlias = _Pointer[RECT]
214+
LPRECT: TypeAlias = _Pointer[RECT]
215+
PRECTL: TypeAlias = _Pointer[RECTL]
216+
LPRECTL: TypeAlias = _Pointer[RECTL]
217+
LPSC_HANDLE: TypeAlias = _Pointer[SC_HANDLE]
218+
PSHORT: TypeAlias = _Pointer[SHORT]
219+
PSIZE: TypeAlias = _Pointer[SIZE]
220+
LPSIZE: TypeAlias = _Pointer[SIZE]
221+
PSIZEL: TypeAlias = _Pointer[SIZEL]
222+
LPSIZEL: TypeAlias = _Pointer[SIZEL]
223+
PSMALL_RECT: TypeAlias = _Pointer[SMALL_RECT]
224+
PUINT: TypeAlias = _Pointer[UINT]
225+
LPUINT: TypeAlias = _Pointer[UINT]
226+
PULARGE_INTEGER: TypeAlias = _Pointer[ULARGE_INTEGER]
227+
PULONG: TypeAlias = _Pointer[ULONG]
228+
PUSHORT: TypeAlias = _Pointer[USHORT]
229+
PWCHAR: TypeAlias = _Pointer[WCHAR]
230+
PWIN32_FIND_DATAA: TypeAlias = _Pointer[WIN32_FIND_DATAA]
231+
LPWIN32_FIND_DATAA: TypeAlias = _Pointer[WIN32_FIND_DATAA]
232+
PWIN32_FIND_DATAW: TypeAlias = _Pointer[WIN32_FIND_DATAW]
233+
LPWIN32_FIND_DATAW: TypeAlias = _Pointer[WIN32_FIND_DATAW]
234+
PWORD: TypeAlias = _Pointer[WORD]
235+
LPWORD: TypeAlias = _Pointer[WORD]

tests/stubtest_allowlists/py3_common.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ ctypes.Array._length_
8484
ctypes.CDLL._FuncPtr # None at class level but initialized in __init__ to this value
8585
ctypes.memmove # CFunctionType
8686
ctypes.memset # CFunctionType
87-
ctypes.pointer # imported C function
8887
ctypes.string_at # docstring argument name is wrong
8988
ctypes.wstring_at # docstring argument name is wrong
9089
distutils.command.bdist_packager # It exists in docs as package name but not in code except as a mention in a comment.

0 commit comments

Comments
 (0)