diff --git a/umsgpack/__init__.pyi b/umsgpack/__init__.pyi index 61a8413..a610978 100644 --- a/umsgpack/__init__.pyi +++ b/umsgpack/__init__.pyi @@ -1,30 +1,44 @@ -from typing import Any +from typing import Any, Callable, Type, TypeVar + +try: + from typing import Protocol +except ImportError: + _SupportsRead = Any + _SupportsWrite = Any +else: + class _SupportsRead(Protocol): + def read(self, __size: int) -> bytes: ... + + class _SupportsWrite(Protocol): + def write(self, __data: bytes) -> Any: ... + +_T = TypeVar("_T") __version__: str version: tuple[int, int, int] -def pack(obj, fp, **options) -> None: ... -def packb(obj, **options) -> bytes: ... -def dump(obj, fp, **options) -> None: ... -def dumps(obj, **options) -> bytes: ... +def pack(obj: Any, fp: _SupportsWrite, **options: Any) -> None: ... +def packb(obj: Any, **options: Any) -> bytes: ... +def dump(obj: Any, fp: _SupportsWrite, **options: Any) -> None: ... +def dumps(obj: Any, **options: Any) -> bytes: ... -def unpackb(s: bytes | bytearray, **options) -> Any: ... -def unpack(fp, **options) -> Any: ... -def loads(s: bytes | bytearray, **options) -> Any: ... -def load(fp, **options) -> Any: ... +def unpackb(s: bytes | bytearray, **options: Any) -> Any: ... +def unpack(fp: _SupportsRead, **options: Any) -> Any: ... +def loads(s: bytes | bytearray, **options: Any) -> Any: ... +def load(fp: _SupportsRead, **options: Any) -> Any: ... class Ext: type: int data: bytes def __init__(self, type: int, data: bytes) -> None: ... - def __eq__(self, other) -> bool: ... - def __ne__(self, other) -> bool: ... + def __eq__(self, other: object) -> bool: ... + def __ne__(self, other: object) -> bool: ... def __hash__(self) -> int: ... class InvalidString(bytes): ... -def ext_serializable(ext_type: int): ... +def ext_serializable(ext_type: int) -> Callable[[Type[_T]], Type[_T]]: ... class PackException(Exception): ... class UnpackException(Exception): ...