Skip to content
Merged
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
8 changes: 4 additions & 4 deletions stdlib/bz2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class _WritableFileobj(Protocol):
# def fileno(self) -> int: ...
# def close(self) -> object: ...

def compress(data: bytes, compresslevel: int = ...) -> bytes: ...
def decompress(data: bytes) -> bytes: ...
def compress(data: ReadableBuffer, compresslevel: int = ...) -> bytes: ...
def decompress(data: ReadableBuffer) -> bytes: ...

_ReadBinaryMode: TypeAlias = Literal["", "r", "rb"]
_WriteBinaryMode: TypeAlias = Literal["w", "wb", "x", "xb", "a", "ab"]
Expand Down Expand Up @@ -132,12 +132,12 @@ class BZ2File(BaseStream, IO[bytes]):
@final
class BZ2Compressor:
def __init__(self, compresslevel: int = ...) -> None: ...
def compress(self, __data: bytes) -> bytes: ...
def compress(self, __data: ReadableBuffer) -> bytes: ...
def flush(self) -> bytes: ...

@final
class BZ2Decompressor:
def decompress(self, data: bytes, max_length: int = ...) -> bytes: ...
def decompress(self, data: ReadableBuffer, max_length: int = ...) -> bytes: ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was a bit concerned here, as decompress uses while data: and I'm not sure if all buffers support that, but it turns out that data is overwritten with BZ2Decompressor.unused_data at the end of the first loop iteration, which appears to be bytes. So if push comes to shove, an empty bytes string is pushed into BZ2Decompressor.decompress() once (which has no effect), and then - since unused_data is now an empty bytes, it will exit the loop.

@property
def eof(self) -> bool: ...
@property
Expand Down