mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-08 21:14:48 +08:00
Use PEP 604 syntax wherever possible (#7493)
This commit is contained in:
@@ -59,9 +59,9 @@ pythonapi: PyDLL
|
||||
# Anything that implements the read-write buffer interface.
|
||||
# The buffer interface is defined purely on the C level, so we cannot define a normal Protocol
|
||||
# for it. Instead we have to list the most common stdlib buffer classes in a Union.
|
||||
_WritableBuffer = _UnionT[bytearray, memoryview, array[Any], _CData]
|
||||
_WritableBuffer = bytearray | memoryview | array[Any] | _CData
|
||||
# Same as _WritableBuffer, but also includes read-only buffer types (like bytes).
|
||||
_ReadOnlyBuffer = _UnionT[_WritableBuffer, bytes]
|
||||
_ReadOnlyBuffer = _WritableBuffer | bytes
|
||||
|
||||
class _CDataMeta(type):
|
||||
# By default mypy complains about the following two methods, because strictly speaking cls
|
||||
@@ -81,7 +81,7 @@ class _CData(metaclass=_CDataMeta):
|
||||
@classmethod
|
||||
def from_address(cls: type[Self], address: int) -> Self: ...
|
||||
@classmethod
|
||||
def from_param(cls: type[_CT], obj: Any) -> _UnionT[_CT, _CArgObject]: ...
|
||||
def from_param(cls: type[_CT], obj: Any) -> _CT | _CArgObject: ...
|
||||
@classmethod
|
||||
def in_dll(cls: type[Self], library: CDLL, name: str) -> Self: ...
|
||||
|
||||
@@ -92,7 +92,7 @@ _ECT = Callable[[Optional[type[_CData]], _FuncPointer, tuple[_CData, ...]], _CDa
|
||||
_PF = _UnionT[tuple[int], tuple[int, str], tuple[int, str, Any]]
|
||||
|
||||
class _FuncPointer(_PointerLike, _CData):
|
||||
restype: _UnionT[type[_CData], Callable[[int], Any], None] = ...
|
||||
restype: type[_CData] | Callable[[int], Any] | None = ...
|
||||
argtypes: Sequence[type[_CData]] = ...
|
||||
errcheck: _ECT = ...
|
||||
@overload
|
||||
@@ -125,25 +125,25 @@ 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 = _UnionT[_PointerLike, Array[Any], _CArgObject, int]
|
||||
_CVoidPLike = _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 = _UnionT[_CVoidPLike, bytes]
|
||||
_CVoidConstPLike = _CVoidPLike | bytes
|
||||
|
||||
def addressof(obj: _CData) -> int: ...
|
||||
def alignment(obj_or_type: _UnionT[_CData, type[_CData]]) -> int: ...
|
||||
def alignment(obj_or_type: _CData | type[_CData]) -> int: ...
|
||||
def byref(obj: _CData, offset: int = ...) -> _CArgObject: ...
|
||||
|
||||
_CastT = TypeVar("_CastT", bound=_CanCastTo)
|
||||
|
||||
def cast(obj: _UnionT[_CData, _CArgObject, int], typ: type[_CastT]) -> _CastT: ...
|
||||
def create_string_buffer(init: _UnionT[int, bytes], size: int | None = ...) -> Array[c_char]: ...
|
||||
def cast(obj: _CData | _CArgObject | int, typ: type[_CastT]) -> _CastT: ...
|
||||
def create_string_buffer(init: int | bytes, size: int | None = ...) -> Array[c_char]: ...
|
||||
|
||||
c_buffer = create_string_buffer
|
||||
|
||||
def create_unicode_buffer(init: _UnionT[int, Text], size: int | None = ...) -> Array[c_wchar]: ...
|
||||
def create_unicode_buffer(init: int | Text, size: int | None = ...) -> Array[c_wchar]: ...
|
||||
|
||||
if sys.platform == "win32":
|
||||
def DllCanUnloadNow() -> int: ...
|
||||
@@ -183,7 +183,7 @@ def set_errno(value: int) -> int: ...
|
||||
if sys.platform == "win32":
|
||||
def set_last_error(value: int) -> int: ...
|
||||
|
||||
def sizeof(obj_or_type: _UnionT[_CData, type[_CData]]) -> int: ...
|
||||
def sizeof(obj_or_type: _CData | type[_CData]) -> int: ...
|
||||
def string_at(address: _CVoidConstPLike, size: int = ...) -> bytes: ...
|
||||
|
||||
if sys.platform == "win32":
|
||||
@@ -198,10 +198,10 @@ class _SimpleCData(Generic[_T], _CData):
|
||||
class c_byte(_SimpleCData[int]): ...
|
||||
|
||||
class c_char(_SimpleCData[bytes]):
|
||||
def __init__(self, value: _UnionT[int, bytes] = ...) -> None: ...
|
||||
def __init__(self, value: int | bytes = ...) -> None: ...
|
||||
|
||||
class c_char_p(_PointerLike, _SimpleCData[Optional[bytes]]):
|
||||
def __init__(self, value: _UnionT[int, bytes] | None = ...) -> None: ...
|
||||
class c_char_p(_PointerLike, _SimpleCData[bytes | None]):
|
||||
def __init__(self, value: int | bytes | None = ...) -> None: ...
|
||||
|
||||
class c_double(_SimpleCData[float]): ...
|
||||
class c_longdouble(_SimpleCData[float]): ...
|
||||
@@ -225,11 +225,11 @@ class c_uint64(_SimpleCData[int]): ...
|
||||
class c_ulong(_SimpleCData[int]): ...
|
||||
class c_ulonglong(_SimpleCData[int]): ...
|
||||
class c_ushort(_SimpleCData[int]): ...
|
||||
class c_void_p(_PointerLike, _SimpleCData[Optional[int]]): ...
|
||||
class c_void_p(_PointerLike, _SimpleCData[int | None]): ...
|
||||
class c_wchar(_SimpleCData[Text]): ...
|
||||
|
||||
class c_wchar_p(_PointerLike, _SimpleCData[Optional[Text]]):
|
||||
def __init__(self, value: _UnionT[int, Text] | None = ...) -> None: ...
|
||||
class c_wchar_p(_PointerLike, _SimpleCData[Text | None]):
|
||||
def __init__(self, value: int | Text | None = ...) -> None: ...
|
||||
|
||||
class c_bool(_SimpleCData[bool]):
|
||||
def __init__(self, value: bool = ...) -> None: ...
|
||||
|
||||
Reference in New Issue
Block a user