mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-25 21:31:09 +08:00
Use TypeAlias where possible for type aliases (#7630)
This commit is contained in:
@@ -2,6 +2,7 @@ import sys
|
||||
from _typeshed import ReadableBuffer, Self, WriteableBuffer
|
||||
from abc import abstractmethod
|
||||
from typing import Any, Callable, ClassVar, Generic, Iterable, Iterator, Mapping, Sequence, TypeVar, Union as _UnionT, overload
|
||||
from typing_extensions import TypeAlias
|
||||
|
||||
if sys.version_info >= (3, 9):
|
||||
from types import GenericAlias
|
||||
@@ -84,8 +85,8 @@ class _CData(metaclass=_CDataMeta):
|
||||
class _CanCastTo(_CData): ...
|
||||
class _PointerLike(_CanCastTo): ...
|
||||
|
||||
_ECT = Callable[[type[_CData] | None, _FuncPointer, tuple[_CData, ...]], _CData]
|
||||
_PF = _UnionT[tuple[int], tuple[int, str], tuple[int, str, Any]]
|
||||
_ECT: TypeAlias = Callable[[type[_CData] | None, _FuncPointer, tuple[_CData, ...]], _CData]
|
||||
_PF: TypeAlias = _UnionT[tuple[int], tuple[int, str], tuple[int, str, Any]]
|
||||
|
||||
class _FuncPointer(_PointerLike, _CData):
|
||||
restype: type[_CData] | Callable[[int], Any] | None
|
||||
@@ -121,12 +122,12 @@ class _CArgObject: ...
|
||||
|
||||
# Any type that can be implicitly converted to c_void_p when passed as a C function argument.
|
||||
# (bytes is not included here, see below.)
|
||||
_CVoidPLike = _PointerLike | Array[Any] | _CArgObject | int
|
||||
_CVoidPLike: TypeAlias = _PointerLike | Array[Any] | _CArgObject | int
|
||||
# Same as above, but including types known to be read-only (i. e. bytes).
|
||||
# This distinction is not strictly necessary (ctypes doesn't differentiate between const
|
||||
# and non-const pointers), but it catches errors like memmove(b'foo', buf, 4)
|
||||
# when memmove(buf, b'foo', 4) was intended.
|
||||
_CVoidConstPLike = _CVoidPLike | bytes
|
||||
_CVoidConstPLike: TypeAlias = _CVoidPLike | bytes
|
||||
|
||||
def addressof(obj: _CData) -> int: ...
|
||||
def alignment(obj_or_type: _CData | type[_CData]) -> int: ...
|
||||
|
||||
@@ -20,6 +20,7 @@ from ctypes import (
|
||||
c_wchar_p,
|
||||
pointer,
|
||||
)
|
||||
from typing_extensions import TypeAlias
|
||||
|
||||
BYTE = c_byte
|
||||
WORD = c_ushort
|
||||
@@ -182,53 +183,53 @@ class WIN32_FIND_DATAW(Structure):
|
||||
|
||||
# These pointer type definitions use pointer[...] instead of POINTER(...), to allow them
|
||||
# to be used in type annotations.
|
||||
PBOOL = pointer[BOOL]
|
||||
LPBOOL = pointer[BOOL]
|
||||
PBOOLEAN = pointer[BOOLEAN]
|
||||
PBYTE = pointer[BYTE]
|
||||
LPBYTE = pointer[BYTE]
|
||||
PCHAR = pointer[CHAR]
|
||||
LPCOLORREF = pointer[COLORREF]
|
||||
PDWORD = pointer[DWORD]
|
||||
LPDWORD = pointer[DWORD]
|
||||
PFILETIME = pointer[FILETIME]
|
||||
LPFILETIME = pointer[FILETIME]
|
||||
PFLOAT = pointer[FLOAT]
|
||||
PHANDLE = pointer[HANDLE]
|
||||
LPHANDLE = pointer[HANDLE]
|
||||
PHKEY = pointer[HKEY]
|
||||
LPHKL = pointer[HKL]
|
||||
PINT = pointer[INT]
|
||||
LPINT = pointer[INT]
|
||||
PLARGE_INTEGER = pointer[LARGE_INTEGER]
|
||||
PLCID = pointer[LCID]
|
||||
PLONG = pointer[LONG]
|
||||
LPLONG = pointer[LONG]
|
||||
PMSG = pointer[MSG]
|
||||
LPMSG = pointer[MSG]
|
||||
PPOINT = pointer[POINT]
|
||||
LPPOINT = pointer[POINT]
|
||||
PPOINTL = pointer[POINTL]
|
||||
PRECT = pointer[RECT]
|
||||
LPRECT = pointer[RECT]
|
||||
PRECTL = pointer[RECTL]
|
||||
LPRECTL = pointer[RECTL]
|
||||
LPSC_HANDLE = pointer[SC_HANDLE]
|
||||
PSHORT = pointer[SHORT]
|
||||
PSIZE = pointer[SIZE]
|
||||
LPSIZE = pointer[SIZE]
|
||||
PSIZEL = pointer[SIZEL]
|
||||
LPSIZEL = pointer[SIZEL]
|
||||
PSMALL_RECT = pointer[SMALL_RECT]
|
||||
PUINT = pointer[UINT]
|
||||
LPUINT = pointer[UINT]
|
||||
PULARGE_INTEGER = pointer[ULARGE_INTEGER]
|
||||
PULONG = pointer[ULONG]
|
||||
PUSHORT = pointer[USHORT]
|
||||
PWCHAR = pointer[WCHAR]
|
||||
PWIN32_FIND_DATAA = pointer[WIN32_FIND_DATAA]
|
||||
LPWIN32_FIND_DATAA = pointer[WIN32_FIND_DATAA]
|
||||
PWIN32_FIND_DATAW = pointer[WIN32_FIND_DATAW]
|
||||
LPWIN32_FIND_DATAW = pointer[WIN32_FIND_DATAW]
|
||||
PWORD = pointer[WORD]
|
||||
LPWORD = pointer[WORD]
|
||||
PBOOL: TypeAlias = pointer[BOOL]
|
||||
LPBOOL: TypeAlias = pointer[BOOL]
|
||||
PBOOLEAN: TypeAlias = pointer[BOOLEAN]
|
||||
PBYTE: TypeAlias = pointer[BYTE]
|
||||
LPBYTE: TypeAlias = pointer[BYTE]
|
||||
PCHAR: TypeAlias = pointer[CHAR]
|
||||
LPCOLORREF: TypeAlias = pointer[COLORREF]
|
||||
PDWORD: TypeAlias = pointer[DWORD]
|
||||
LPDWORD: TypeAlias = pointer[DWORD]
|
||||
PFILETIME: TypeAlias = pointer[FILETIME]
|
||||
LPFILETIME: TypeAlias = pointer[FILETIME]
|
||||
PFLOAT: TypeAlias = pointer[FLOAT]
|
||||
PHANDLE: TypeAlias = pointer[HANDLE]
|
||||
LPHANDLE: TypeAlias = pointer[HANDLE]
|
||||
PHKEY: TypeAlias = pointer[HKEY]
|
||||
LPHKL: TypeAlias = pointer[HKL]
|
||||
PINT: TypeAlias = pointer[INT]
|
||||
LPINT: TypeAlias = pointer[INT]
|
||||
PLARGE_INTEGER: TypeAlias = pointer[LARGE_INTEGER]
|
||||
PLCID: TypeAlias = pointer[LCID]
|
||||
PLONG: TypeAlias = pointer[LONG]
|
||||
LPLONG: TypeAlias = pointer[LONG]
|
||||
PMSG: TypeAlias = pointer[MSG]
|
||||
LPMSG: TypeAlias = pointer[MSG]
|
||||
PPOINT: TypeAlias = pointer[POINT]
|
||||
LPPOINT: TypeAlias = pointer[POINT]
|
||||
PPOINTL: TypeAlias = pointer[POINTL]
|
||||
PRECT: TypeAlias = pointer[RECT]
|
||||
LPRECT: TypeAlias = pointer[RECT]
|
||||
PRECTL: TypeAlias = pointer[RECTL]
|
||||
LPRECTL: TypeAlias = pointer[RECTL]
|
||||
LPSC_HANDLE: TypeAlias = pointer[SC_HANDLE]
|
||||
PSHORT: TypeAlias = pointer[SHORT]
|
||||
PSIZE: TypeAlias = pointer[SIZE]
|
||||
LPSIZE: TypeAlias = pointer[SIZE]
|
||||
PSIZEL: TypeAlias = pointer[SIZEL]
|
||||
LPSIZEL: TypeAlias = pointer[SIZEL]
|
||||
PSMALL_RECT: TypeAlias = pointer[SMALL_RECT]
|
||||
PUINT: TypeAlias = pointer[UINT]
|
||||
LPUINT: TypeAlias = pointer[UINT]
|
||||
PULARGE_INTEGER: TypeAlias = pointer[ULARGE_INTEGER]
|
||||
PULONG: TypeAlias = pointer[ULONG]
|
||||
PUSHORT: TypeAlias = pointer[USHORT]
|
||||
PWCHAR: TypeAlias = pointer[WCHAR]
|
||||
PWIN32_FIND_DATAA: TypeAlias = pointer[WIN32_FIND_DATAA]
|
||||
LPWIN32_FIND_DATAA: TypeAlias = pointer[WIN32_FIND_DATAA]
|
||||
PWIN32_FIND_DATAW: TypeAlias = pointer[WIN32_FIND_DATAW]
|
||||
LPWIN32_FIND_DATAW: TypeAlias = pointer[WIN32_FIND_DATAW]
|
||||
PWORD: TypeAlias = pointer[WORD]
|
||||
LPWORD: TypeAlias = pointer[WORD]
|
||||
|
||||
Reference in New Issue
Block a user