Skip to content

pickletools: accepts bytearray #9073

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions stdlib/pickle.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
from _typeshed import ReadableBuffer
from _typeshed import ReadableBuffer, SupportsWrite
from collections.abc import Callable, Iterable, Iterator, Mapping
from typing import Any, ClassVar, Protocol, SupportsBytes, Union
from typing_extensions import SupportsIndex, TypeAlias, final
Expand Down Expand Up @@ -97,9 +97,6 @@ class _ReadableFileobj(Protocol):
def read(self, __n: int) -> bytes: ...
def readline(self) -> bytes: ...

class _WritableFileobj(Protocol):
def write(self, __b: bytes) -> Any: ...

if sys.version_info >= (3, 8):
@final
class PickleBuffer:
Expand All @@ -109,7 +106,7 @@ if sys.version_info >= (3, 8):
_BufferCallback: TypeAlias = Callable[[PickleBuffer], Any] | None
def dump(
obj: Any,
file: _WritableFileobj,
file: SupportsWrite[bytes],
protocol: int | None = ...,
*,
fix_imports: bool = ...,
Expand All @@ -136,7 +133,7 @@ if sys.version_info >= (3, 8):
) -> Any: ...

else:
def dump(obj: Any, file: _WritableFileobj, protocol: int | None = ..., *, fix_imports: bool = ...) -> None: ...
def dump(obj: Any, file: SupportsWrite[bytes], protocol: int | None = ..., *, fix_imports: bool = ...) -> None: ...
def dumps(obj: Any, protocol: int | None = ..., *, fix_imports: bool = ...) -> bytes: ...
def load(file: _ReadableFileobj, *, fix_imports: bool = ..., encoding: str = ..., errors: str = ...) -> Any: ...
def loads(data: ReadableBuffer, *, fix_imports: bool = ..., encoding: str = ..., errors: str = ...) -> Any: ...
Expand All @@ -162,15 +159,15 @@ class Pickler:
if sys.version_info >= (3, 8):
def __init__(
self,
file: _WritableFileobj,
file: SupportsWrite[bytes],
protocol: int | None = ...,
*,
fix_imports: bool = ...,
buffer_callback: _BufferCallback = ...,
) -> None: ...
def reducer_override(self, obj: Any) -> Any: ...
else:
def __init__(self, file: _WritableFileobj, protocol: int | None = ..., *, fix_imports: bool = ...) -> None: ...
def __init__(self, file: SupportsWrite[bytes], protocol: int | None = ..., *, fix_imports: bool = ...) -> None: ...

def dump(self, __obj: Any) -> None: ...
def clear_memo(self) -> None: ...
Expand Down
6 changes: 3 additions & 3 deletions stdlib/pickletools.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ class OpcodeInfo:

opcodes: list[OpcodeInfo]

def genops(pickle: bytes | IO[bytes]) -> Iterator[tuple[OpcodeInfo, Any | None, int | None]]: ...
def optimize(p: bytes | IO[bytes]) -> bytes: ...
def genops(pickle: bytes | bytearray | IO[bytes]) -> Iterator[tuple[OpcodeInfo, Any | None, int | None]]: ...
def optimize(p: bytes | bytearray | IO[bytes]) -> bytes: ...
def dis(
pickle: bytes | IO[bytes],
pickle: bytes | bytearray | IO[bytes],
out: IO[str] | None = ...,
memo: MutableMapping[int, Any] | None = ...,
indentlevel: int = ...,
Expand Down