1+ from _typeshed import ReadableBuffer
12import sys
23from collections .abc import Callable , Iterable , Iterator , Mapping
3- from typing import Any , ClassVar , Protocol , Union
4+ from typing import Any , ClassVar , Protocol , Union , SupportsBytes , SupportsIndex
45from typing_extensions import TypeAlias , final
56
67if sys .version_info >= (3 , 8 ):
@@ -183,11 +184,9 @@ class _WritableFileobj(Protocol):
183184 def write (self , __b : bytes ) -> Any : ...
184185
185186if 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,14 @@ 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 , * , fix_imports : bool = ..., encoding : str = ..., errors : str = ..., buffers : Iterable [Any ] | None = ...
215214 ) -> Any : ...
216215
217216else :
218217 def dump (obj : Any , file : _WritableFileobj , protocol : int | None = ..., * , fix_imports : bool = ...) -> None : ...
219218 def dumps (obj : Any , protocol : int | None = ..., * , fix_imports : bool = ...) -> bytes : ...
220219 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 : ...
220+ def loads (data : ReadableBuffer , * , fix_imports : bool = ..., encoding : str = ..., errors : str = ...) -> Any : ...
222221
223222class PickleError (Exception ): ...
224223class PicklingError (PickleError ): ...
@@ -359,7 +358,7 @@ if sys.version_info >= (3, 8):
359358 READONLY_BUFFER : bytes
360359
361360def encode_long (x : int ) -> bytes : ... # undocumented
362- def decode_long (data : bytes ) -> int : ... # undocumented
361+ def decode_long (data : Iterable [ SupportsIndex ] | SupportsBytes | ReadableBuffer ) -> int : ... # undocumented
363362
364363# pure-Python implementations
365364_Pickler = Pickler # undocumented
0 commit comments