From 4abca3f5bf977ca0aacdb8e1c1299a50f7fde71b Mon Sep 17 00:00:00 2001 From: Rogdham Date: Thu, 5 Jun 2025 19:19:28 +0200 Subject: [PATCH 1/2] Python 3.14: PEP-784 zstd in other modules --- .../compression/{bz2/__init__.pyi => bz2.pyi} | 0 .../{gzip/__init__.pyi => gzip.pyi} | 0 .../{lzma/__init__.pyi => lzma.pyi} | 0 .../{zlib/__init__.pyi => zlib.pyi} | 0 stdlib/tarfile.pyi | 121 +++++++++++++++++- 5 files changed, 117 insertions(+), 4 deletions(-) rename stdlib/compression/{bz2/__init__.pyi => bz2.pyi} (100%) rename stdlib/compression/{gzip/__init__.pyi => gzip.pyi} (100%) rename stdlib/compression/{lzma/__init__.pyi => lzma.pyi} (100%) rename stdlib/compression/{zlib/__init__.pyi => zlib.pyi} (100%) diff --git a/stdlib/compression/bz2/__init__.pyi b/stdlib/compression/bz2.pyi similarity index 100% rename from stdlib/compression/bz2/__init__.pyi rename to stdlib/compression/bz2.pyi diff --git a/stdlib/compression/gzip/__init__.pyi b/stdlib/compression/gzip.pyi similarity index 100% rename from stdlib/compression/gzip/__init__.pyi rename to stdlib/compression/gzip.pyi diff --git a/stdlib/compression/lzma/__init__.pyi b/stdlib/compression/lzma.pyi similarity index 100% rename from stdlib/compression/lzma/__init__.pyi rename to stdlib/compression/lzma.pyi diff --git a/stdlib/compression/zlib/__init__.pyi b/stdlib/compression/zlib.pyi similarity index 100% rename from stdlib/compression/zlib/__init__.pyi rename to stdlib/compression/zlib.pyi diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 31094f87872d..2a4b3306acb8 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -9,6 +9,9 @@ from types import TracebackType from typing import IO, ClassVar, Literal, Protocol, overload from typing_extensions import Self, TypeAlias, deprecated +if sys.version_info >= (3, 14): + from compression.zstd import ZstdDict + __all__ = [ "TarFile", "TarInfo", @@ -184,6 +187,30 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + if sys.version_info >= (3, 14): + @overload + @classmethod + def open( + cls, + name: StrOrBytesPath | None, + mode: Literal["r:zst"], + fileobj: _Fileobj | None = None, + bufsize: int = 10240, + *, + format: int | None = ..., + tarinfo: type[TarInfo] | None = ..., + dereference: bool | None = ..., + ignore_zeros: bool | None = ..., + encoding: str | None = ..., + errors: str = ..., + pax_headers: Mapping[str, str] | None = ..., + debug: int | None = ..., + errorlevel: int | None = ..., + level: None = None, + options: Mapping[int, int] | None = None, + zstd_dict: ZstdDict | None = None, + ) -> Self: ... + @overload @classmethod def open( @@ -302,12 +329,56 @@ class TarFile: errorlevel: int | None = ..., preset: Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | None = ..., ) -> Self: ... + if sys.version_info >= (3, 14): + @overload + @classmethod + def open( + cls, + name: StrOrBytesPath | None, + mode: Literal["x:zst", "w:zst"], + fileobj: _Fileobj | None = None, + bufsize: int = 10240, + *, + format: int | None = ..., + tarinfo: type[TarInfo] | None = ..., + dereference: bool | None = ..., + ignore_zeros: bool | None = ..., + encoding: str | None = ..., + errors: str = ..., + pax_headers: Mapping[str, str] | None = ..., + debug: int | None = ..., + errorlevel: int | None = ..., + options: Mapping[int, int] | None = None, + zstd_dict: ZstdDict | None = None, + ) -> Self: ... + @overload + @classmethod + def open( + cls, + name: StrOrBytesPath | None = None, + *, + mode: Literal["x:zst", "w:zst"], + fileobj: _Fileobj | None = None, + bufsize: int = 10240, + format: int | None = ..., + tarinfo: type[TarInfo] | None = ..., + dereference: bool | None = ..., + ignore_zeros: bool | None = ..., + encoding: str | None = ..., + errors: str = ..., + pax_headers: Mapping[str, str] | None = ..., + debug: int | None = ..., + errorlevel: int | None = ..., + options: Mapping[int, int] | None = None, + zstd_dict: ZstdDict | None = None, + ) -> Self: ... + @overload @classmethod def open( cls, name: StrOrBytesPath | ReadableBuffer | None, - mode: Literal["r|*", "r|", "r|gz", "r|bz2", "r|xz"], + mode: Literal["r|*", "r|", "r|gz", "r|bz2", "r|xz", "r|zst"], fileobj: _Fileobj | None = None, bufsize: int = 10240, *, @@ -327,7 +398,7 @@ class TarFile: cls, name: StrOrBytesPath | ReadableBuffer | None = None, *, - mode: Literal["r|*", "r|", "r|gz", "r|bz2", "r|xz"], + mode: Literal["r|*", "r|", "r|gz", "r|bz2", "r|xz", "r|zst"], fileobj: _Fileobj | None = None, bufsize: int = 10240, format: int | None = ..., @@ -345,7 +416,7 @@ class TarFile: def open( cls, name: StrOrBytesPath | WriteableBuffer | None, - mode: Literal["w|", "w|xz"], + mode: Literal["w|", "w|xz", "w|zst"], fileobj: _Fileobj | None = None, bufsize: int = 10240, *, @@ -365,7 +436,7 @@ class TarFile: cls, name: StrOrBytesPath | WriteableBuffer | None = None, *, - mode: Literal["w|", "w|xz"], + mode: Literal["w|", "w|xz", "w|zst"], fileobj: _Fileobj | None = None, bufsize: int = 10240, format: int | None = ..., @@ -524,6 +595,48 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + if sys.version_info >= (3, 14): + @overload + @classmethod + def zstopen( + cls, + name: StrOrBytesPath | None, + mode: Literal["r"] = "r", + fileobj: IO[bytes] | None = None, + level: None = None, + options: Mapping[int, int] | None = None, + zstd_dict: ZstdDict | None = None, + *, + format: int | None = ..., + tarinfo: type[TarInfo] | None = ..., + dereference: bool | None = ..., + ignore_zeros: bool | None = ..., + encoding: str | None = ..., + pax_headers: Mapping[str, str] | None = ..., + debug: int | None = ..., + errorlevel: int | None = ..., + ) -> Self: ... + @overload + @classmethod + def zstopen( + cls, + name: StrOrBytesPath | None, + mode: Literal["w", "x"], + fileobj: IO[bytes] | None = None, + level: int | None = None, + options: Mapping[int, int] | None = None, + zstd_dict: ZstdDict | None = None, + *, + format: int | None = ..., + tarinfo: type[TarInfo] | None = ..., + dereference: bool | None = ..., + ignore_zeros: bool | None = ..., + encoding: str | None = ..., + pax_headers: Mapping[str, str] | None = ..., + debug: int | None = ..., + errorlevel: int | None = ..., + ) -> Self: ... + def getmember(self, name: str) -> TarInfo: ... def getmembers(self) -> _list[TarInfo]: ... def getnames(self) -> _list[str]: ... From d54b29ed4838c37bbd14bef20dc81655b1036c9c Mon Sep 17 00:00:00 2001 From: Rogdham Date: Thu, 5 Jun 2025 19:45:32 +0200 Subject: [PATCH 2/2] Fix allowlist on py314 --- stdlib/@tests/stubtest_allowlists/py314.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/stdlib/@tests/stubtest_allowlists/py314.txt b/stdlib/@tests/stubtest_allowlists/py314.txt index 6d312dacd027..2698d5f86e13 100644 --- a/stdlib/@tests/stubtest_allowlists/py314.txt +++ b/stdlib/@tests/stubtest_allowlists/py314.txt @@ -22,7 +22,6 @@ multiprocessing.managers._BaseDictProxy.__ror__ multiprocessing.managers._BaseDictProxy.fromkeys multiprocessing.process.BaseProcess.interrupt multiprocessing.synchronize.SemLock.locked -tarfile.TarFile.zstopen tkinter.Event.__class_getitem__ # =========================