From a7d4183677ab727d3766f0f8627ef51ad96c83d9 Mon Sep 17 00:00:00 2001 From: Max Muoto Date: Sat, 7 Jun 2025 20:47:01 -0500 Subject: [PATCH 01/13] Update zstopen for 3.14 --- stdlib/@tests/stubtest_allowlists/py314.txt | 1 - stdlib/tarfile.pyi | 50 ++++++++++++++++----- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/py314.txt b/stdlib/@tests/stubtest_allowlists/py314.txt index 53dd45eac25e..62d032eb6965 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__ # ========================= diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index a18ef0b823f9..918ccbf418a4 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -4,9 +4,10 @@ import sys from _typeshed import ReadableBuffer, StrOrBytesPath, StrPath, SupportsRead, WriteableBuffer from builtins import list as _list # aliases to avoid name clashes with fields named "type" or "list" from collections.abc import Callable, Iterable, Iterator, Mapping +from compression.zstd import ZstdDict from gzip import _ReadableFileobj as _GzipReadableFileobj, _WritableFileobj as _GzipWritableFileobj from types import TracebackType -from typing import IO, ClassVar, Literal, Protocol, overload +from typing import IO, ClassVar, Literal, Protocol, TypedDict, overload from typing_extensions import Self, TypeAlias, deprecated __all__ = [ @@ -105,6 +106,17 @@ PAX_NAME_FIELDS: set[str] ENCODING: str +class _TarOptions(TypedDict, total=False): + compresslevel: int + 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 + class ExFileObject(io.BufferedReader): def __init__(self, tarfile: TarFile, tarinfo: TarInfo) -> None: ... @@ -426,16 +438,7 @@ class TarFile: name: StrOrBytesPath | None, mode: Literal["r", "a", "w", "x"] = "r", fileobj: _Fileobj | None = None, - *, - compresslevel: int = ..., - 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 = ..., + **kwargs: _TarOptions, ) -> Self: ... @overload @classmethod @@ -587,6 +590,31 @@ class TarFile: self, name: StrOrBytesPath | None = None, arcname: str | None = None, fileobj: IO[bytes] | None = None ) -> TarInfo: ... def close(self) -> None: ... + if sys.version_info >= (3, 14): + @classmethod + @overload + def zstopen( + cls, + name: StrOrBytesPath | None, + mode: Literal["r", "rb"] = "r", + fileobj: _Fileobj | None = None, + level: None = None, + options: Mapping[int, int] | None = None, + zstd_dict: ZstdDict | None = None, + **kwargs: _TarOptions, + ) -> Self: ... + @classmethod + @overload + def zstopen( + cls, + name: StrOrBytesPath | None, + mode: Literal["w", "x"], + fileobj: _Fileobj | None = None, + level: int | None = None, + options: Mapping[int, int] | None = None, + zstd_dict: ZstdDict | None = None, + **kwargs: _TarOptions, + ) -> Self: ... open = TarFile.open From 538827cb9124c610593f61d7ef8c0e5faffff632 Mon Sep 17 00:00:00 2001 From: Max Muoto Date: Sat, 7 Jun 2025 20:49:10 -0500 Subject: [PATCH 02/13] Tweak --- stdlib/tarfile.pyi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 918ccbf418a4..09b2bd9ff373 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -106,7 +106,7 @@ PAX_NAME_FIELDS: set[str] ENCODING: str -class _TarOptions(TypedDict, total=False): +class _TarOpenOptions(TypedDict, total=False): compresslevel: int format: int | None tarinfo: type[TarInfo] | None @@ -438,7 +438,7 @@ class TarFile: name: StrOrBytesPath | None, mode: Literal["r", "a", "w", "x"] = "r", fileobj: _Fileobj | None = None, - **kwargs: _TarOptions, + **kwargs: _TarOpenOptions, ) -> Self: ... @overload @classmethod @@ -601,7 +601,7 @@ class TarFile: level: None = None, options: Mapping[int, int] | None = None, zstd_dict: ZstdDict | None = None, - **kwargs: _TarOptions, + **kwargs: _TarOpenOptions, ) -> Self: ... @classmethod @overload @@ -613,7 +613,7 @@ class TarFile: level: int | None = None, options: Mapping[int, int] | None = None, zstd_dict: ZstdDict | None = None, - **kwargs: _TarOptions, + **kwargs: _TarOpenOptions, ) -> Self: ... open = TarFile.open From a1dad285b413d83f40017d30010a41a1f3529520 Mon Sep 17 00:00:00 2001 From: Max Muoto Date: Sat, 7 Jun 2025 20:51:13 -0500 Subject: [PATCH 03/13] Fix import --- stdlib/tarfile.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 09b2bd9ff373..29c542bb3ff5 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -4,7 +4,6 @@ import sys from _typeshed import ReadableBuffer, StrOrBytesPath, StrPath, SupportsRead, WriteableBuffer from builtins import list as _list # aliases to avoid name clashes with fields named "type" or "list" from collections.abc import Callable, Iterable, Iterator, Mapping -from compression.zstd import ZstdDict from gzip import _ReadableFileobj as _GzipReadableFileobj, _WritableFileobj as _GzipWritableFileobj from types import TracebackType from typing import IO, ClassVar, Literal, Protocol, TypedDict, overload @@ -591,6 +590,8 @@ class TarFile: ) -> TarInfo: ... def close(self) -> None: ... if sys.version_info >= (3, 14): + from compression.zstd import ZstdDict + @classmethod @overload def zstopen( From 81a20ecd99b2d6bd32cbe53057b5fc8039a6c941 Mon Sep 17 00:00:00 2001 From: Max Muoto Date: Sat, 7 Jun 2025 20:56:52 -0500 Subject: [PATCH 04/13] Tweak --- stdlib/tarfile.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 29c542bb3ff5..d812ef87d8ea 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -590,7 +590,7 @@ class TarFile: ) -> TarInfo: ... def close(self) -> None: ... if sys.version_info >= (3, 14): - from compression.zstd import ZstdDict + from _zstd import ZstdDict @classmethod @overload From 2f411c1f3f38df90dd083159e0ebc348cf9e89c8 Mon Sep 17 00:00:00 2001 From: Max Muoto Date: Sat, 7 Jun 2025 21:15:04 -0500 Subject: [PATCH 05/13] Tweak --- stdlib/tarfile.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index d812ef87d8ea..29c542bb3ff5 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -590,7 +590,7 @@ class TarFile: ) -> TarInfo: ... def close(self) -> None: ... if sys.version_info >= (3, 14): - from _zstd import ZstdDict + from compression.zstd import ZstdDict @classmethod @overload From e78fea484ee169b0c8bb44422f859f706281c927 Mon Sep 17 00:00:00 2001 From: Max Muoto Date: Sat, 7 Jun 2025 21:18:05 -0500 Subject: [PATCH 06/13] Tweak --- stdlib/tarfile.pyi | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 29c542bb3ff5..98c4f940d23a 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -6,7 +6,7 @@ from builtins import list as _list # aliases to avoid name clashes with fields from collections.abc import Callable, Iterable, Iterator, Mapping from gzip import _ReadableFileobj as _GzipReadableFileobj, _WritableFileobj as _GzipWritableFileobj from types import TracebackType -from typing import IO, ClassVar, Literal, Protocol, TypedDict, overload +from typing import IO, ClassVar, TYPE_CHECKING, Literal, Protocol, TypedDict, overload from typing_extensions import Self, TypeAlias, deprecated __all__ = [ @@ -590,7 +590,8 @@ class TarFile: ) -> TarInfo: ... def close(self) -> None: ... if sys.version_info >= (3, 14): - from compression.zstd import ZstdDict + if TYPE_CHECKING: + from compression.zstd import ZstdDict @classmethod @overload From 79c8934ec4f50e9a4258e6310c994a32374a7648 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 8 Jun 2025 02:19:57 +0000 Subject: [PATCH 07/13] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/tarfile.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 98c4f940d23a..869bcc5835b7 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -6,7 +6,7 @@ from builtins import list as _list # aliases to avoid name clashes with fields from collections.abc import Callable, Iterable, Iterator, Mapping from gzip import _ReadableFileobj as _GzipReadableFileobj, _WritableFileobj as _GzipWritableFileobj from types import TracebackType -from typing import IO, ClassVar, TYPE_CHECKING, Literal, Protocol, TypedDict, overload +from typing import IO, TYPE_CHECKING, ClassVar, Literal, Protocol, TypedDict, overload from typing_extensions import Self, TypeAlias, deprecated __all__ = [ From 5181622bf207fd0853f3a83a0637a87ab7f28bb9 Mon Sep 17 00:00:00 2001 From: Max Muoto Date: Sat, 7 Jun 2025 21:22:25 -0500 Subject: [PATCH 08/13] test --- stdlib/tarfile.pyi | 48 +++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 869bcc5835b7..6a37eaf5b250 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -593,30 +593,30 @@ class TarFile: if TYPE_CHECKING: from compression.zstd import ZstdDict - @classmethod - @overload - def zstopen( - cls, - name: StrOrBytesPath | None, - mode: Literal["r", "rb"] = "r", - fileobj: _Fileobj | None = None, - level: None = None, - options: Mapping[int, int] | None = None, - zstd_dict: ZstdDict | None = None, - **kwargs: _TarOpenOptions, - ) -> Self: ... - @classmethod - @overload - def zstopen( - cls, - name: StrOrBytesPath | None, - mode: Literal["w", "x"], - fileobj: _Fileobj | None = None, - level: int | None = None, - options: Mapping[int, int] | None = None, - zstd_dict: ZstdDict | None = None, - **kwargs: _TarOpenOptions, - ) -> Self: ... + @classmethod + @overload + def zstopen( + cls, + name: StrOrBytesPath | None, + mode: Literal["r", "rb"] = "r", + fileobj: _Fileobj | None = None, + level: None = None, + options: Mapping[int, int] | None = None, + zstd_dict: ZstdDict | None = None, + **kwargs: _TarOpenOptions, + ) -> Self: ... + @classmethod + @overload + def zstopen( + cls, + name: StrOrBytesPath | None, + mode: Literal["w", "x"], + fileobj: _Fileobj | None = None, + level: int | None = None, + options: Mapping[int, int] | None = None, + zstd_dict: ZstdDict | None = None, + **kwargs: _TarOpenOptions, + ) -> Self: ... open = TarFile.open From aa8e9e97a5e544a84854bac9bbe7b51dde6864d3 Mon Sep 17 00:00:00 2001 From: Max Muoto Date: Sat, 7 Jun 2025 21:24:13 -0500 Subject: [PATCH 09/13] Test runtime --- stdlib/tarfile.pyi | 55 +++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 6a37eaf5b250..c006da59bc96 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -6,7 +6,7 @@ from builtins import list as _list # aliases to avoid name clashes with fields from collections.abc import Callable, Iterable, Iterator, Mapping from gzip import _ReadableFileobj as _GzipReadableFileobj, _WritableFileobj as _GzipWritableFileobj from types import TracebackType -from typing import IO, TYPE_CHECKING, ClassVar, Literal, Protocol, TypedDict, overload +from typing import IO, ClassVar, Literal, Protocol, TypedDict, overload from typing_extensions import Self, TypeAlias, deprecated __all__ = [ @@ -590,33 +590,32 @@ class TarFile: ) -> TarInfo: ... def close(self) -> None: ... if sys.version_info >= (3, 14): - if TYPE_CHECKING: - from compression.zstd import ZstdDict - - @classmethod - @overload - def zstopen( - cls, - name: StrOrBytesPath | None, - mode: Literal["r", "rb"] = "r", - fileobj: _Fileobj | None = None, - level: None = None, - options: Mapping[int, int] | None = None, - zstd_dict: ZstdDict | None = None, - **kwargs: _TarOpenOptions, - ) -> Self: ... - @classmethod - @overload - def zstopen( - cls, - name: StrOrBytesPath | None, - mode: Literal["w", "x"], - fileobj: _Fileobj | None = None, - level: int | None = None, - options: Mapping[int, int] | None = None, - zstd_dict: ZstdDict | None = None, - **kwargs: _TarOpenOptions, - ) -> Self: ... + from compression.zstd import ZstdDict + + @classmethod + @overload + def zstopen( + cls, + name: StrOrBytesPath | None, + mode: Literal["r", "rb"] = "r", + fileobj: _Fileobj | None = None, + level: None = None, + options: Mapping[int, int] | None = None, + zstd_dict: "ZstdDict | None" = None, + **kwargs: _TarOpenOptions, + ) -> Self: ... + @classmethod + @overload + def zstopen( + cls, + name: StrOrBytesPath | None, + mode: Literal["w", "x"], + fileobj: _Fileobj | None = None, + level: int | None = None, + options: Mapping[int, int] | None = None, + zstd_dict: "ZstdDict | None" = None, + **kwargs: _TarOpenOptions, + ) -> Self: ... open = TarFile.open From 02eccae46d5fad3e266a867127bcf954e436b685 Mon Sep 17 00:00:00 2001 From: Max Muoto Date: Sat, 7 Jun 2025 21:25:49 -0500 Subject: [PATCH 10/13] Tweak --- stdlib/tarfile.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index c006da59bc96..29c542bb3ff5 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -601,7 +601,7 @@ class TarFile: fileobj: _Fileobj | None = None, level: None = None, options: Mapping[int, int] | None = None, - zstd_dict: "ZstdDict | None" = None, + zstd_dict: ZstdDict | None = None, **kwargs: _TarOpenOptions, ) -> Self: ... @classmethod @@ -613,7 +613,7 @@ class TarFile: fileobj: _Fileobj | None = None, level: int | None = None, options: Mapping[int, int] | None = None, - zstd_dict: "ZstdDict | None" = None, + zstd_dict: ZstdDict | None = None, **kwargs: _TarOpenOptions, ) -> Self: ... From 29a33c423f57e1309e3a6df6b48134d111ef1d6c Mon Sep 17 00:00:00 2001 From: Max Muoto Date: Sat, 7 Jun 2025 21:26:03 -0500 Subject: [PATCH 11/13] Tweak --- stdlib/tarfile.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 29c542bb3ff5..7d3dcf1b89fd 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -590,7 +590,7 @@ class TarFile: ) -> TarInfo: ... def close(self) -> None: ... if sys.version_info >= (3, 14): - from compression.zstd import ZstdDict + import compression.zstd @classmethod @overload @@ -601,7 +601,7 @@ class TarFile: fileobj: _Fileobj | None = None, level: None = None, options: Mapping[int, int] | None = None, - zstd_dict: ZstdDict | None = None, + zstd_dict: compression.zstd.ZstdDict | None = None, **kwargs: _TarOpenOptions, ) -> Self: ... @classmethod @@ -613,7 +613,7 @@ class TarFile: fileobj: _Fileobj | None = None, level: int | None = None, options: Mapping[int, int] | None = None, - zstd_dict: ZstdDict | None = None, + zstd_dict: compression.zstd.ZstdDict | None = None, **kwargs: _TarOpenOptions, ) -> Self: ... From 0913723a6351554a3e0492a072f14fe24338f134 Mon Sep 17 00:00:00 2001 From: Max Muoto Date: Sat, 7 Jun 2025 21:28:26 -0500 Subject: [PATCH 12/13] Tweak --- stdlib/tarfile.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 7d3dcf1b89fd..59952c155d8c 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -590,7 +590,7 @@ class TarFile: ) -> TarInfo: ... def close(self) -> None: ... if sys.version_info >= (3, 14): - import compression.zstd + from compression.zstd import ZstdDict as ZstdDict @classmethod @overload @@ -601,7 +601,7 @@ class TarFile: fileobj: _Fileobj | None = None, level: None = None, options: Mapping[int, int] | None = None, - zstd_dict: compression.zstd.ZstdDict | None = None, + zstd_dict: ZstdDict | None = None, **kwargs: _TarOpenOptions, ) -> Self: ... @classmethod @@ -613,7 +613,7 @@ class TarFile: fileobj: _Fileobj | None = None, level: int | None = None, options: Mapping[int, int] | None = None, - zstd_dict: compression.zstd.ZstdDict | None = None, + zstd_dict: ZstdDict | None = None, **kwargs: _TarOpenOptions, ) -> Self: ... From 8a0a8c95c72a0d528a6994672fc537522ac026c7 Mon Sep 17 00:00:00 2001 From: Max Muoto Date: Sat, 7 Jun 2025 21:30:07 -0500 Subject: [PATCH 13/13] Test --- stdlib/tarfile.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 59952c155d8c..3163ad6e4b4b 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -590,7 +590,7 @@ class TarFile: ) -> TarInfo: ... def close(self) -> None: ... if sys.version_info >= (3, 14): - from compression.zstd import ZstdDict as ZstdDict + from compression.zstd import ZstdDict as _ZstdDict @classmethod @overload @@ -601,7 +601,7 @@ class TarFile: fileobj: _Fileobj | None = None, level: None = None, options: Mapping[int, int] | None = None, - zstd_dict: ZstdDict | None = None, + zstd_dict: _ZstdDict | None = None, **kwargs: _TarOpenOptions, ) -> Self: ... @classmethod @@ -613,7 +613,7 @@ class TarFile: fileobj: _Fileobj | None = None, level: int | None = None, options: Mapping[int, int] | None = None, - zstd_dict: ZstdDict | None = None, + zstd_dict: _ZstdDict | None = None, **kwargs: _TarOpenOptions, ) -> Self: ...