1
1
import sys
2
+ from _typeshed import ReadableBuffer
2
3
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
5
6
6
7
if sys .version_info >= (3 , 8 ):
7
8
__all__ = [
@@ -183,11 +184,9 @@ class _WritableFileobj(Protocol):
183
184
def write (self , __b : bytes ) -> Any : ...
184
185
185
186
if sys .version_info >= (3 , 8 ):
186
- # TODO: holistic design for buffer interface (typing.Buffer?)
187
187
@final
188
188
class PickleBuffer :
189
- # buffer must be a buffer-providing object
190
- def __init__ (self , buffer : Any ) -> None : ...
189
+ def __init__ (self , buffer : ReadableBuffer ) -> None : ...
191
190
def raw (self ) -> memoryview : ...
192
191
def release (self ) -> None : ...
193
192
_BufferCallback : TypeAlias = Callable [[PickleBuffer ], Any ] | None
@@ -211,14 +210,19 @@ if sys.version_info >= (3, 8):
211
210
buffers : Iterable [Any ] | None = ...,
212
211
) -> Any : ...
213
212
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 = ...,
215
219
) -> Any : ...
216
220
217
221
else :
218
222
def dump (obj : Any , file : _WritableFileobj , protocol : int | None = ..., * , fix_imports : bool = ...) -> None : ...
219
223
def dumps (obj : Any , protocol : int | None = ..., * , fix_imports : bool = ...) -> bytes : ...
220
224
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 : ...
222
226
223
227
class PickleError (Exception ): ...
224
228
class PicklingError (PickleError ): ...
@@ -359,7 +363,7 @@ if sys.version_info >= (3, 8):
359
363
READONLY_BUFFER : bytes
360
364
361
365
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
363
367
364
368
# pure-Python implementations
365
369
_Pickler = Pickler # undocumented
0 commit comments