mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-09 05:24:52 +08:00
Move some pointer-related definitions from ctypes/__init__.pyi to _ctypes.pyi (#10133)
This commit is contained in:
@@ -2,7 +2,7 @@ import sys
|
||||
from _typeshed import ReadableBuffer, WriteableBuffer
|
||||
from abc import abstractmethod
|
||||
from collections.abc import Iterable, Iterator, Mapping, Sequence
|
||||
from ctypes import CDLL, _CArgObject, _PointerLike
|
||||
from ctypes import CDLL, _CArgObject
|
||||
from typing import Any, Generic, TypeVar, overload
|
||||
from typing_extensions import Self, TypeAlias
|
||||
|
||||
@@ -70,6 +70,25 @@ class _SimpleCData(Generic[_T], _CData):
|
||||
# but we can't use overloads without creating many, many mypy false-positive errors
|
||||
def __init__(self, value: _T = ...) -> None: ... # pyright: ignore[reportInvalidTypeVarUse]
|
||||
|
||||
class _CanCastTo(_CData): ...
|
||||
class _PointerLike(_CanCastTo): ...
|
||||
|
||||
class _Pointer(Generic[_CT], _PointerLike, _CData):
|
||||
_type_: type[_CT]
|
||||
contents: _CT
|
||||
@overload
|
||||
def __init__(self) -> None: ...
|
||||
@overload
|
||||
def __init__(self, arg: _CT) -> None: ...
|
||||
@overload
|
||||
def __getitem__(self, __key: int) -> Any: ...
|
||||
@overload
|
||||
def __getitem__(self, __key: slice) -> list[Any]: ...
|
||||
def __setitem__(self, __key: int, __value: Any) -> None: ...
|
||||
|
||||
def POINTER(type: type[_CT]) -> type[_Pointer[_CT]]: ...
|
||||
def pointer(__arg: _CT) -> _Pointer[_CT]: ...
|
||||
|
||||
class _CField:
|
||||
offset: int
|
||||
size: int
|
||||
|
||||
@@ -1,20 +1,25 @@
|
||||
import sys
|
||||
from _ctypes import (
|
||||
POINTER as POINTER,
|
||||
RTLD_GLOBAL as RTLD_GLOBAL,
|
||||
RTLD_LOCAL as RTLD_LOCAL,
|
||||
ArgumentError as ArgumentError,
|
||||
Array as Array,
|
||||
Structure as Structure,
|
||||
Union as Union,
|
||||
_CanCastTo as _CanCastTo,
|
||||
_CData as _CData,
|
||||
_CDataMeta as _CDataMeta,
|
||||
_CField as _CField,
|
||||
_Pointer as _Pointer,
|
||||
_PointerLike as _PointerLike,
|
||||
_SimpleCData as _SimpleCData,
|
||||
_StructUnionBase as _StructUnionBase,
|
||||
_StructUnionMeta as _StructUnionMeta,
|
||||
addressof as addressof,
|
||||
alignment as alignment,
|
||||
get_errno as get_errno,
|
||||
pointer as pointer,
|
||||
resize as resize,
|
||||
set_errno as set_errno,
|
||||
sizeof as sizeof,
|
||||
@@ -31,7 +36,6 @@ if sys.version_info >= (3, 9):
|
||||
|
||||
_T = TypeVar("_T")
|
||||
_DLLT = TypeVar("_DLLT", bound=CDLL)
|
||||
_CT = TypeVar("_CT", bound=_CData)
|
||||
|
||||
DEFAULT_MODE: int
|
||||
|
||||
@@ -85,9 +89,6 @@ if sys.platform == "win32":
|
||||
pydll: LibraryLoader[PyDLL]
|
||||
pythonapi: PyDLL
|
||||
|
||||
class _CanCastTo(_CData): ...
|
||||
class _PointerLike(_CanCastTo): ...
|
||||
|
||||
_ECT: TypeAlias = Callable[[type[_CData] | None, _FuncPointer, tuple[_CData, ...]], _CData]
|
||||
_PF: TypeAlias = tuple[int] | tuple[int, str] | tuple[int, str, Any]
|
||||
|
||||
@@ -148,22 +149,6 @@ if sys.platform == "win32":
|
||||
|
||||
def memmove(dst: _CVoidPLike, src: _CVoidConstPLike, count: int) -> int: ...
|
||||
def memset(dst: _CVoidPLike, c: int, count: int) -> int: ...
|
||||
def POINTER(type: type[_CT]) -> type[_Pointer[_CT]]: ...
|
||||
|
||||
class _Pointer(Generic[_CT], _PointerLike, _CData):
|
||||
_type_: type[_CT]
|
||||
contents: _CT
|
||||
@overload
|
||||
def __init__(self) -> None: ...
|
||||
@overload
|
||||
def __init__(self, arg: _CT) -> None: ...
|
||||
@overload
|
||||
def __getitem__(self, __key: int) -> Any: ...
|
||||
@overload
|
||||
def __getitem__(self, __key: slice) -> list[Any]: ...
|
||||
def __setitem__(self, __key: int, __value: Any) -> None: ...
|
||||
|
||||
def pointer(__arg: _CT) -> _Pointer[_CT]: ...
|
||||
def string_at(address: _CVoidConstPLike, size: int = -1) -> bytes: ...
|
||||
|
||||
if sys.platform == "win32":
|
||||
|
||||
@@ -335,7 +335,6 @@ wave.Wave_read.initfp
|
||||
wave.Wave_write.initfp
|
||||
|
||||
_ctypes.CFuncPtr
|
||||
_ctypes.POINTER
|
||||
_ctypes.PyObj_FromPtr
|
||||
_ctypes.Py_DECREF
|
||||
_ctypes.Py_INCREF
|
||||
@@ -343,7 +342,6 @@ _ctypes.buffer_info
|
||||
_ctypes.byref
|
||||
_ctypes.call_cdeclfunction
|
||||
_ctypes.call_function
|
||||
_ctypes.pointer
|
||||
|
||||
# ==========
|
||||
# Allowlist entries that cannot or should not be fixed
|
||||
|
||||
Reference in New Issue
Block a user