Skip to content

Commit 00f4031

Browse files
pickle: accept ReadableBuffer (#7678)
1 parent 2a0fc1b commit 00f4031

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

stdlib/pickle.pyi

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import sys
2+
from _typeshed import ReadableBuffer
23
from collections.abc import Callable, Iterable, Iterator, Mapping
3-
from typing import Any, ClassVar, Protocol, Union
4-
from typing_extensions import TypeAlias, final
4+
from typing import Any, ClassVar, Protocol, SupportsBytes, Union
5+
from typing_extensions import SupportsIndex, TypeAlias, final
56

67
if sys.version_info >= (3, 8):
78
__all__ = [
@@ -183,11 +184,9 @@ class _WritableFileobj(Protocol):
183184
def write(self, __b: bytes) -> Any: ...
184185

185186
if sys.version_info >= (3, 8):
186-
# TODO: holistic design for buffer interface (typing.Buffer?)
187187
@final
188188
class PickleBuffer:
189-
# buffer must be a buffer-providing object
190-
def __init__(self, buffer: Any) -> None: ...
189+
def __init__(self, buffer: ReadableBuffer) -> None: ...
191190
def raw(self) -> memoryview: ...
192191
def release(self) -> None: ...
193192
_BufferCallback: TypeAlias = Callable[[PickleBuffer], Any] | None
@@ -211,14 +210,19 @@ if sys.version_info >= (3, 8):
211210
buffers: Iterable[Any] | None = ...,
212211
) -> Any: ...
213212
def loads(
214-
__data: bytes, *, fix_imports: bool = ..., encoding: str = ..., errors: str = ..., buffers: Iterable[Any] | None = ...
213+
__data: ReadableBuffer,
214+
*,
215+
fix_imports: bool = ...,
216+
encoding: str = ...,
217+
errors: str = ...,
218+
buffers: Iterable[Any] | None = ...,
215219
) -> Any: ...
216220

217221
else:
218222
def dump(obj: Any, file: _WritableFileobj, protocol: int | None = ..., *, fix_imports: bool = ...) -> None: ...
219223
def dumps(obj: Any, protocol: int | None = ..., *, fix_imports: bool = ...) -> bytes: ...
220224
def load(file: _ReadableFileobj, *, fix_imports: bool = ..., encoding: str = ..., errors: str = ...) -> Any: ...
221-
def loads(data: bytes, *, fix_imports: bool = ..., encoding: str = ..., errors: str = ...) -> Any: ...
225+
def loads(data: ReadableBuffer, *, fix_imports: bool = ..., encoding: str = ..., errors: str = ...) -> Any: ...
222226

223227
class PickleError(Exception): ...
224228
class PicklingError(PickleError): ...
@@ -359,7 +363,7 @@ if sys.version_info >= (3, 8):
359363
READONLY_BUFFER: bytes
360364

361365
def encode_long(x: int) -> bytes: ... # undocumented
362-
def decode_long(data: bytes) -> int: ... # undocumented
366+
def decode_long(data: Iterable[SupportsIndex] | SupportsBytes | ReadableBuffer) -> int: ... # undocumented
363367

364368
# pure-Python implementations
365369
_Pickler = Pickler # undocumented

0 commit comments

Comments
 (0)