Move Structure and Union from ctypes/__init__.pyi to _ctypes.pyi (#10125)

This commit is contained in:
Jun Komoda
2023-05-01 21:01:41 +09:00
committed by GitHub
parent ae0c9f9dad
commit 295a5c3e7a
3 changed files with 24 additions and 21 deletions

View File

@@ -1,7 +1,7 @@
import sys
from _typeshed import ReadableBuffer, WriteableBuffer
from abc import abstractmethod
from collections.abc import Iterable, Iterator, Mapping
from collections.abc import Iterable, Iterator, Mapping, Sequence
from ctypes import CDLL, _CArgObject, _PointerLike
from typing import Any, Generic, TypeVar, overload
from typing_extensions import Self, TypeAlias
@@ -66,6 +66,24 @@ 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 _CField:
offset: int
size: int
class _StructUnionMeta(_CDataMeta):
_fields_: Sequence[tuple[str, type[_CData]] | tuple[str, type[_CData], int]]
_pack_: int
_anonymous_: Sequence[str]
def __getattr__(self, name: str) -> _CField: ...
class _StructUnionBase(_CData, metaclass=_StructUnionMeta):
def __init__(self, *args: Any, **kw: Any) -> None: ...
def __getattr__(self, name: str) -> Any: ...
def __setattr__(self, name: str, value: Any) -> None: ...
class Union(_StructUnionBase): ...
class Structure(_StructUnionBase): ...
class Array(Generic[_CT], _CData):
@property
@abstractmethod

View File

@@ -3,9 +3,14 @@ from _ctypes import (
RTLD_GLOBAL as RTLD_GLOBAL,
RTLD_LOCAL as RTLD_LOCAL,
Array as Array,
Structure as Structure,
Union as Union,
_CData as _CData,
_CDataMeta as _CDataMeta,
_CField as _CField,
_SimpleCData as _SimpleCData,
_StructUnionBase as _StructUnionBase,
_StructUnionMeta as _StructUnionMeta,
)
from collections.abc import Callable, Sequence
from typing import Any, ClassVar, Generic, TypeVar, overload
@@ -216,23 +221,5 @@ if sys.platform == "win32":
class HRESULT(_SimpleCData[int]): ... # TODO undocumented
class py_object(_CanCastTo, _SimpleCData[_T]): ...
class _CField:
offset: int
size: int
class _StructUnionMeta(_CDataMeta):
_fields_: Sequence[tuple[str, type[_CData]] | tuple[str, type[_CData], int]]
_pack_: int
_anonymous_: Sequence[str]
def __getattr__(self, name: str) -> _CField: ...
class _StructUnionBase(_CData, metaclass=_StructUnionMeta):
def __init__(self, *args: Any, **kw: Any) -> None: ...
def __getattr__(self, name: str) -> Any: ...
def __setattr__(self, name: str, value: Any) -> None: ...
class Union(_StructUnionBase): ...
class Structure(_StructUnionBase): ...
class BigEndianStructure(Structure): ...
class LittleEndianStructure(Structure): ...

View File

@@ -339,8 +339,6 @@ _ctypes.POINTER
_ctypes.PyObj_FromPtr
_ctypes.Py_DECREF
_ctypes.Py_INCREF
_ctypes.Structure
_ctypes.Union
_ctypes.addressof
_ctypes.alignment
_ctypes.buffer_info