Skip to content
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
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ extra-standard-library = [
# Extra modules not recognized by Ruff
# Added in Python 3.9
"zoneinfo",
# Added in Python 3.14
"compression",
]
known-first-party = ["_utils", "ts_utils"]

Expand Down
11 changes: 5 additions & 6 deletions stdlib/@tests/stubtest_allowlists/py314.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
_asyncio.all_tasks
_asyncio.future_add_to_awaited_by
_asyncio.future_discard_from_awaited_by
_compression
_ctypes.POINTER
_ctypes.byref
_ctypes.pointer
Expand Down Expand Up @@ -70,11 +69,11 @@ builtins.staticmethod.__annotate__
builtins.staticmethod.__class_getitem__
code.compile_command
codeop.compile_command
compression
compression.bz2
compression.gzip
compression.lzma
compression.zlib
compression.gzip.GzipFile.readinto
compression.gzip.GzipFile.readinto
compression.gzip.GzipFile.readinto1
compression.gzip.GzipFile.readinto1
compression.gzip.compress
compression.zstd
concurrent.futures.__all__
concurrent.futures.InterpreterPoolExecutor
Expand Down
1 change: 1 addition & 0 deletions stdlib/@tests/stubtest_allowlists/win32-py314.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ asyncio.windows_events.WindowsSelectorEventLoopPolicy
asyncio.windows_events._DefaultEventLoopPolicy
asyncio.windows_events._WindowsProactorEventLoopPolicy
asyncio.windows_events._WindowsSelectorEventLoopPolicy
compression.zlib.ZLIBNG_VERSION
ctypes.c_double_complex
ctypes.c_float_complex
ctypes.c_longdouble_complex
Expand Down
3 changes: 2 additions & 1 deletion stdlib/VERSIONS
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ _bz2: 3.3-
_codecs: 3.0-
_collections_abc: 3.3-
_compat_pickle: 3.1-
_compression: 3.5-
_compression: 3.5-3.13
_contextvars: 3.7-
_csv: 3.0-
_ctypes: 3.0-
Expand Down Expand Up @@ -118,6 +118,7 @@ collections: 3.0-
collections.abc: 3.3-
colorsys: 3.0-
compileall: 3.0-
compression: 3.14-
concurrent: 3.2-
configparser: 3.0-
contextlib: 3.0-
Expand Down
8 changes: 5 additions & 3 deletions stdlib/_compression.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from _typeshed import WriteableBuffer
# _compression is replaced by compression._common._streams on Python 3.14+ (PEP-784)

from _typeshed import Incomplete, WriteableBuffer
from collections.abc import Callable
from io import DEFAULT_BUFFER_SIZE, BufferedIOBase, RawIOBase
from typing import Any, Protocol
Expand All @@ -16,9 +18,9 @@ class DecompressReader(RawIOBase):
def __init__(
self,
fp: _Reader,
decomp_factory: Callable[..., object],
decomp_factory: Callable[..., Incomplete],
trailing_error: type[Exception] | tuple[type[Exception], ...] = (),
**decomp_args: Any,
**decomp_args: Any, # These are passed to decomp_factory.
) -> None: ...
def readinto(self, b: WriteableBuffer) -> int: ...
def read(self, size: int = -1) -> bytes: ...
Expand Down
10 changes: 7 additions & 3 deletions stdlib/bz2.pyi
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import _compression
import sys
from _bz2 import BZ2Compressor as BZ2Compressor, BZ2Decompressor as BZ2Decompressor
from _compression import BaseStream
from _typeshed import ReadableBuffer, StrOrBytesPath, WriteableBuffer
from collections.abc import Iterable
from typing import IO, Literal, Protocol, SupportsIndex, TextIO, overload
from typing_extensions import Self, TypeAlias

if sys.version_info >= (3, 14):
from compression._common._streams import BaseStream, _Reader
else:
from _compression import BaseStream, _Reader

__all__ = ["BZ2File", "BZ2Compressor", "BZ2Decompressor", "open", "compress", "decompress"]

# The following attributes and methods are optional:
# def fileno(self) -> int: ...
# def close(self) -> object: ...
class _ReadableFileobj(_compression._Reader, Protocol): ...
class _ReadableFileobj(_Reader, Protocol): ...

class _WritableFileobj(Protocol):
def write(self, b: bytes, /) -> object: ...
Expand Down
Empty file added stdlib/compression/__init__.pyi
Empty file.
Empty file.
25 changes: 25 additions & 0 deletions stdlib/compression/_common/_streams.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from _typeshed import Incomplete, WriteableBuffer
from collections.abc import Callable
from io import DEFAULT_BUFFER_SIZE, BufferedIOBase, RawIOBase
from typing import Any, Protocol

BUFFER_SIZE = DEFAULT_BUFFER_SIZE

class _Reader(Protocol):
def read(self, n: int, /) -> bytes: ...
def seekable(self) -> bool: ...
def seek(self, n: int, /) -> Any: ...

class BaseStream(BufferedIOBase): ...

class DecompressReader(RawIOBase):
def __init__(
self,
fp: _Reader,
decomp_factory: Callable[..., Incomplete], # Consider backporting changes to _compression
trailing_error: type[Exception] | tuple[type[Exception], ...] = (),
**decomp_args: Any, # These are passed to decomp_factory.
) -> None: ...
def readinto(self, b: WriteableBuffer) -> int: ...
def read(self, size: int = -1) -> bytes: ...
def seek(self, offset: int, whence: int = 0) -> int: ...
1 change: 1 addition & 0 deletions stdlib/compression/bz2/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from bz2 import *
1 change: 1 addition & 0 deletions stdlib/compression/gzip/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from gzip import *
1 change: 1 addition & 0 deletions stdlib/compression/lzma/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from lzma import *
1 change: 1 addition & 0 deletions stdlib/compression/zlib/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from zlib import *
10 changes: 7 additions & 3 deletions stdlib/gzip.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import _compression
import sys
import zlib
from _typeshed import ReadableBuffer, SizedBuffer, StrOrBytesPath
from io import FileIO, TextIOWrapper
from typing import Final, Literal, Protocol, overload
from typing_extensions import TypeAlias

if sys.version_info >= (3, 14):
from compression._common._streams import BaseStream, DecompressReader
else:
from _compression import BaseStream, DecompressReader

__all__ = ["BadGzipFile", "GzipFile", "open", "compress", "decompress"]

_ReadBinaryMode: TypeAlias = Literal["r", "rb"]
Expand Down Expand Up @@ -84,7 +88,7 @@ class _PaddedFile:

class BadGzipFile(OSError): ...

class GzipFile(_compression.BaseStream):
class GzipFile(BaseStream):
myfileobj: FileIO | None
mode: object
name: str
Expand Down Expand Up @@ -153,7 +157,7 @@ class GzipFile(_compression.BaseStream):
def seek(self, offset: int, whence: int = 0) -> int: ...
def readline(self, size: int | None = -1) -> bytes: ...

class _GzipReader(_compression.DecompressReader):
class _GzipReader(DecompressReader):
def __init__(self, fp: _ReadableFileobj) -> None: ...

def compress(data: SizedBuffer, compresslevel: int = 9, *, mtime: float | None = None) -> bytes: ...
Expand Down
7 changes: 6 additions & 1 deletion stdlib/lzma.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from _compression import BaseStream
import sys
from _lzma import (
CHECK_CRC32 as CHECK_CRC32,
CHECK_CRC64 as CHECK_CRC64,
Expand Down Expand Up @@ -38,6 +38,11 @@ from _typeshed import ReadableBuffer, StrOrBytesPath
from typing import IO, Literal, TextIO, overload
from typing_extensions import Self, TypeAlias

if sys.version_info >= (3, 14):
from compression._common._streams import BaseStream
else:
from _compression import BaseStream

__all__ = [
"CHECK_NONE",
"CHECK_CRC32",
Expand Down