diff --git a/stdlib/2and3/pickle.pyi b/stdlib/2and3/pickle.pyi index ec9353f6b751..99c047d47fe3 100644 --- a/stdlib/2and3/pickle.pyi +++ b/stdlib/2and3/pickle.pyi @@ -1,20 +1,49 @@ import sys -from typing import Any, IO, Mapping, Union, Tuple, Callable, Optional, Iterator +from typing import Any, IO, Mapping, Union, Tuple, Callable, Optional, Iterable, Iterator HIGHEST_PROTOCOL: int if sys.version_info >= (3, 0): DEFAULT_PROTOCOL: int -if sys.version_info >= (3, 0): +if sys.version_info >= (3, 8): + # TODO: holistic design for buffer interface (typing.Buffer?) + + class PickleBuffer: + # buffer must be a buffer-providing object + def __init__(self, buffer: Any) -> None: ... + def raw(self) -> memoryview: ... + def release(self) -> None: ... + + _BufferCallback = Optional[Callable[[PickleBuffer], Any]] + + def dump( + obj: Any, file: IO[bytes], protocol: Optional[int] = ..., *, + fix_imports: bool = ..., + buffer_callback: _BufferCallback = ... + ) -> None: ... + def dumps( + obj: Any, protocol: Optional[int] = ..., *, + fix_imports: bool = ..., + buffer_callback: _BufferCallback = ... + ) -> bytes: ... + def load( + file: IO[bytes], *, fix_imports: bool = ..., encoding: str = ..., + errors: str = ..., buffers: Optional[Iterable[Any]] = ... + ) -> Any: ... + def loads( + data: bytes, *, fix_imports: bool = ..., encoding: str = ..., + errors: str = ..., buffers: Optional[Iterable[Any]] = ... + ) -> Any: ... +elif sys.version_info >= (3, 0): def dump(obj: Any, file: IO[bytes], protocol: Optional[int] = ..., *, fix_imports: bool = ...) -> None: ... def dumps(obj: Any, protocol: Optional[int] = ..., *, fix_imports: bool = ...) -> bytes: ... - def loads(bytes_object: bytes, *, fix_imports: bool = ..., - encoding: str = ..., errors: str = ...) -> Any: ... def load(file: IO[bytes], *, fix_imports: bool = ..., encoding: str = ..., errors: str = ...) -> Any: ... + def loads(data: bytes, *, fix_imports: bool = ..., + encoding: str = ..., errors: str = ...) -> Any: ... else: def dump(obj: Any, file: IO[bytes], protocol: Optional[int] = ...) -> None: ... def dumps(obj: Any, protocol: Optional[int] = ...) -> bytes: ... @@ -39,7 +68,12 @@ class Pickler: if sys.version_info >= (3, 3): dispatch_table: Mapping[type, Callable[[Any], _reducedtype]] - if sys.version_info >= (3, 0): + if sys.version_info >= (3, 8): + def __init__(self, file: IO[bytes], protocol: Optional[int] = ..., *, + fix_imports: bool = ..., buffer_callback: _BufferCallback = ... + ) -> None: ... + def reducer_override(self, obj: Any) -> Any: ... + elif sys.version_info >= (3, 0): def __init__(self, file: IO[bytes], protocol: Optional[int] = ..., *, fix_imports: bool = ...) -> None: ... else: @@ -52,7 +86,11 @@ class Pickler: def reducer_override(self, obj: Any) -> Any: ... class Unpickler: - if sys.version_info >= (3, 0): + if sys.version_info >= (3, 8): + def __init__(self, file: IO[bytes], *, fix_imports: bool = ..., + encoding: str = ..., errors: str = ..., + buffers: Optional[Iterable[Any]] = ...) -> None: ... + elif sys.version_info >= (3, 0): def __init__(self, file: IO[bytes], *, fix_imports: bool = ..., encoding: str = ..., errors: str = ...) -> None: ... else: