mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-08 13:04:46 +08:00
use new union syntax in ctypes/__init__.pyi (#5883)
This commit is contained in:
@@ -38,21 +38,16 @@ class CDLL(object):
|
||||
if sys.version_info >= (3, 8):
|
||||
def __init__(
|
||||
self,
|
||||
name: Optional[str],
|
||||
name: str | None,
|
||||
mode: int = ...,
|
||||
handle: Optional[int] = ...,
|
||||
handle: int | None = ...,
|
||||
use_errno: bool = ...,
|
||||
use_last_error: bool = ...,
|
||||
winmode: Optional[int] = ...,
|
||||
winmode: int | None = ...,
|
||||
) -> None: ...
|
||||
else:
|
||||
def __init__(
|
||||
self,
|
||||
name: Optional[str],
|
||||
mode: int = ...,
|
||||
handle: Optional[int] = ...,
|
||||
use_errno: bool = ...,
|
||||
use_last_error: bool = ...,
|
||||
self, name: str | None, mode: int = ..., handle: int | None = ..., use_errno: bool = ..., use_last_error: bool = ...
|
||||
) -> None: ...
|
||||
def __getattr__(self, name: str) -> _NamedFuncPointer: ...
|
||||
def __getitem__(self, name: str) -> _NamedFuncPointer: ...
|
||||
@@ -95,7 +90,7 @@ class _CDataMeta(type):
|
||||
class _CData(metaclass=_CDataMeta):
|
||||
_b_base: int = ...
|
||||
_b_needsfree_: bool = ...
|
||||
_objects: Optional[Mapping[Any, int]] = ...
|
||||
_objects: Mapping[Any, int] | None = ...
|
||||
@classmethod
|
||||
def from_buffer(cls: Type[_CT], source: _WritableBuffer, offset: int = ...) -> _CT: ...
|
||||
@classmethod
|
||||
@@ -103,7 +98,7 @@ class _CData(metaclass=_CDataMeta):
|
||||
@classmethod
|
||||
def from_address(cls: Type[_CT], address: int) -> _CT: ...
|
||||
@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[_CT], library: CDLL, name: str) -> _CT: ...
|
||||
|
||||
@@ -114,7 +109,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
|
||||
@@ -122,7 +117,7 @@ class _FuncPointer(_PointerLike, _CData):
|
||||
@overload
|
||||
def __init__(self, callable: Callable[..., Any]) -> None: ...
|
||||
@overload
|
||||
def __init__(self, func_spec: Tuple[_UnionT[str, int], CDLL], paramflags: Tuple[_PF, ...] = ...) -> None: ...
|
||||
def __init__(self, func_spec: Tuple[str | int, CDLL], paramflags: Tuple[_PF, ...] = ...) -> None: ...
|
||||
@overload
|
||||
def __init__(self, vtlb_index: int, name: str, paramflags: Tuple[_PF, ...] = ..., iid: pointer[c_int] = ...) -> None: ...
|
||||
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
|
||||
@@ -133,15 +128,15 @@ class _NamedFuncPointer(_FuncPointer):
|
||||
class ArgumentError(Exception): ...
|
||||
|
||||
def CFUNCTYPE(
|
||||
restype: Optional[Type[_CData]], *argtypes: Type[_CData], use_errno: bool = ..., use_last_error: bool = ...
|
||||
restype: Type[_CData] | None, *argtypes: Type[_CData], use_errno: bool = ..., use_last_error: bool = ...
|
||||
) -> Type[_FuncPointer]: ...
|
||||
|
||||
if sys.platform == "win32":
|
||||
def WINFUNCTYPE(
|
||||
restype: Optional[Type[_CData]], *argtypes: Type[_CData], use_errno: bool = ..., use_last_error: bool = ...
|
||||
restype: Type[_CData] | None, *argtypes: Type[_CData], use_errno: bool = ..., use_last_error: bool = ...
|
||||
) -> Type[_FuncPointer]: ...
|
||||
|
||||
def PYFUNCTYPE(restype: Optional[Type[_CData]], *argtypes: Type[_CData]) -> Type[_FuncPointer]: ...
|
||||
def PYFUNCTYPE(restype: Type[_CData] | None, *argtypes: Type[_CData]) -> Type[_FuncPointer]: ...
|
||||
|
||||
class _CArgObject: ...
|
||||
|
||||
@@ -155,17 +150,17 @@ _CVoidPLike = _UnionT[_PointerLike, Array[Any], _CArgObject, int]
|
||||
_CVoidConstPLike = _UnionT[_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: Optional[int] = ...) -> 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, str], size: Optional[int] = ...) -> Array[c_wchar]: ...
|
||||
def create_unicode_buffer(init: int | str, size: int | None = ...) -> Array[c_wchar]: ...
|
||||
|
||||
if sys.platform == "win32":
|
||||
def DllCanUnloadNow() -> int: ...
|
||||
@@ -204,11 +199,11 @@ 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":
|
||||
def WinError(code: Optional[int] = ..., descr: Optional[str] = ...) -> OSError: ...
|
||||
def WinError(code: int | None = ..., descr: str | None = ...) -> OSError: ...
|
||||
|
||||
def wstring_at(address: _CVoidConstPLike, size: int = ...) -> str: ...
|
||||
|
||||
@@ -219,10 +214,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: Optional[_UnionT[int, bytes]] = ...) -> None: ...
|
||||
def __init__(self, value: int | bytes | None = ...) -> None: ...
|
||||
|
||||
class c_double(_SimpleCData[float]): ...
|
||||
class c_longdouble(_SimpleCData[float]): ...
|
||||
@@ -250,7 +245,7 @@ class c_void_p(_PointerLike, _SimpleCData[Optional[int]]): ...
|
||||
class c_wchar(_SimpleCData[str]): ...
|
||||
|
||||
class c_wchar_p(_PointerLike, _SimpleCData[Optional[str]]):
|
||||
def __init__(self, value: Optional[_UnionT[int, str]] = ...) -> None: ...
|
||||
def __init__(self, value: int | str | None = ...) -> None: ...
|
||||
|
||||
class c_bool(_SimpleCData[bool]):
|
||||
def __init__(self, value: bool = ...) -> None: ...
|
||||
@@ -265,7 +260,7 @@ class _CField:
|
||||
size: int = ...
|
||||
|
||||
class _StructUnionMeta(_CDataMeta):
|
||||
_fields_: Sequence[_UnionT[Tuple[str, Type[_CData]], Tuple[str, Type[_CData], int]]] = ...
|
||||
_fields_: Sequence[Tuple[str, Type[_CData]] | Tuple[str, Type[_CData], int]] = ...
|
||||
_pack_: int = ...
|
||||
_anonymous_: Sequence[str] = ...
|
||||
def __getattr__(self, name: str) -> _CField: ...
|
||||
|
||||
Reference in New Issue
Block a user