Skip to content

Commit 05c0a1d

Browse files
authored
move byref-related definitions from ctypes/__init__.pyi to _ctypes.pyi (#10137)
1 parent ec1130a commit 05c0a1d

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

stdlib/_ctypes.pyi

Lines changed: 5 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
5+
from ctypes import CDLL
66
from typing import Any, Generic, TypeVar, overload
77
from typing_extensions import Self, TypeAlias
88

@@ -89,6 +89,10 @@ class _Pointer(Generic[_CT], _PointerLike, _CData):
8989
def POINTER(type: type[_CT]) -> type[_Pointer[_CT]]: ...
9090
def pointer(__arg: _CT) -> _Pointer[_CT]: ...
9191

92+
class _CArgObject: ...
93+
94+
def byref(obj: _CData, offset: int = ...) -> _CArgObject: ...
95+
9296
class _CField:
9397
offset: int
9498
size: int

stdlib/ctypes/__init__.pyi

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ from _ctypes import (
88
Structure as Structure,
99
Union as Union,
1010
_CanCastTo as _CanCastTo,
11+
_CArgObject as _CArgObject,
1112
_CData as _CData,
1213
_CDataMeta as _CDataMeta,
1314
_CField as _CField,
@@ -18,6 +19,7 @@ from _ctypes import (
1819
_StructUnionMeta as _StructUnionMeta,
1920
addressof as addressof,
2021
alignment as alignment,
22+
byref as byref,
2123
get_errno as get_errno,
2224
pointer as pointer,
2325
resize as resize,
@@ -120,8 +122,6 @@ if sys.platform == "win32":
120122

121123
def PYFUNCTYPE(restype: type[_CData] | None, *argtypes: type[_CData]) -> type[_FuncPointer]: ...
122124

123-
class _CArgObject: ...
124-
125125
# Any type that can be implicitly converted to c_void_p when passed as a C function argument.
126126
# (bytes is not included here, see below.)
127127
_CVoidPLike: TypeAlias = _PointerLike | Array[Any] | _CArgObject | int
@@ -131,8 +131,6 @@ _CVoidPLike: TypeAlias = _PointerLike | Array[Any] | _CArgObject | int
131131
# when memmove(buf, b'foo', 4) was intended.
132132
_CVoidConstPLike: TypeAlias = _CVoidPLike | bytes
133133

134-
def byref(obj: _CData, offset: int = ...) -> _CArgObject: ...
135-
136134
_CastT = TypeVar("_CastT", bound=_CanCastTo)
137135

138136
def cast(obj: _CData | _CArgObject | int, typ: type[_CastT]) -> _CastT: ...

tests/stubtest_allowlists/py3_common.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ _ctypes.PyObj_FromPtr
339339
_ctypes.Py_DECREF
340340
_ctypes.Py_INCREF
341341
_ctypes.buffer_info
342-
_ctypes.byref
343342
_ctypes.call_cdeclfunction
344343
_ctypes.call_function
345344

0 commit comments

Comments
 (0)