From 4391d312c6544d366cba7ae9a1ba7ab473e7755f Mon Sep 17 00:00:00 2001 From: Alexeev Bronislav Date: Tue, 27 May 2025 17:26:11 +0700 Subject: [PATCH 01/36] start fixing issue 14168 with TarFile --- stdlib/tarfile.pyi | 73 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 31094f87872d..2bb62f86f6ac 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -142,6 +142,44 @@ class TarFile: copybufsize: int | None = None, # undocumented stream: bool = False, ) -> None: ... + + @overload + def __init__( # noqa: F811 + self, + name: StrOrBytesPath | None, + mode: Literal["r", "a", "w", "x"] = "r", + fileobj: _Fileobj | None = None, + format: int | None = None, + tarinfo: type[TarInfo] | None = None, + dereference: bool | None = None, + ignore_zeros: bool | None = None, + encoding: str | None = None, + errors: str = "surrogateescape", + pax_headers: Mapping[str, str] | None = None, + debug: int | None = None, + errorlevel: int | None = None, + copybufsize: int | None = None, # undocumented + stream: bool = False, + ) -> None: ... + + @overload + def __init__( + self, + fileobj: _Fileobj, + name: StrOrBytesPath | None = None, + mode: Literal["r", "a", "w", "x"] = "r", + format: int | None = None, + tarinfo: type[TarInfo] | None = None, + dereference: bool | None = None, + ignore_zeros: bool | None = None, + encoding: str | None = None, + errors: str = "surrogateescape", + pax_headers: Mapping[str, str] | None = None, + debug: int | None = None, + errorlevel: int | None = None, + copybufsize: int | None = None, # undocumented + stream: bool = False, + ) -> None: ... else: def __init__( self, @@ -160,6 +198,41 @@ class TarFile: copybufsize: int | None = None, # undocumented ) -> None: ... + @overload + def __init__( # noqa: F811 + self, + name: StrOrBytesPath | None, + mode: Literal["r", "a", "w", "x"] = "r", + fileobj: _Fileobj | None = None, + format: int | None = None, + tarinfo: type[TarInfo] | None = None, + dereference: bool | None = None, + ignore_zeros: bool | None = None, + encoding: str | None = None, + errors: str = "surrogateescape", + pax_headers: Mapping[str, str] | None = None, + debug: int | None = None, + errorlevel: int | None = None, + copybufsize: int | None = None, # undocumented + ) -> None: ... + + def __init__( + self, + fileobj: _Fileobj, + name: StrOrBytesPath | None = None, + mode: Literal["r", "a", "w", "x"] = "r", + format: int | None = None, + tarinfo: type[TarInfo] | None = None, + dereference: bool | None = None, + ignore_zeros: bool | None = None, + encoding: str | None = None, + errors: str = "surrogateescape", + pax_headers: Mapping[str, str] | None = None, + debug: int | None = None, + errorlevel: int | None = None, + copybufsize: int | None = None, # undocumented + ) -> None: ... + def __enter__(self) -> Self: ... def __exit__( self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None From 17704405184dc6c36287a61ca6683493f5423431 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 27 May 2025 10:36:36 +0000 Subject: [PATCH 02/36] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/tarfile.pyi | 4 ---- 1 file changed, 4 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 2bb62f86f6ac..7bff6a430297 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -142,7 +142,6 @@ class TarFile: copybufsize: int | None = None, # undocumented stream: bool = False, ) -> None: ... - @overload def __init__( # noqa: F811 self, @@ -161,7 +160,6 @@ class TarFile: copybufsize: int | None = None, # undocumented stream: bool = False, ) -> None: ... - @overload def __init__( self, @@ -197,7 +195,6 @@ class TarFile: errorlevel: int | None = None, copybufsize: int | None = None, # undocumented ) -> None: ... - @overload def __init__( # noqa: F811 self, @@ -215,7 +212,6 @@ class TarFile: errorlevel: int | None = None, copybufsize: int | None = None, # undocumented ) -> None: ... - def __init__( self, fileobj: _Fileobj, From 6b387d5b348918fafe50deffbf0f6ca5e9984f5c Mon Sep 17 00:00:00 2001 From: Alexeev Bronislav Date: Tue, 27 May 2025 17:52:53 +0700 Subject: [PATCH 03/36] fix errors with `__init__`, start add @override for other methods of TarFile --- stdlib/tarfile.pyi | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 2bb62f86f6ac..cbf424c47c5c 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -142,11 +142,10 @@ class TarFile: copybufsize: int | None = None, # undocumented stream: bool = False, ) -> None: ... - @overload def __init__( # noqa: F811 self, - name: StrOrBytesPath | None, + name: StrOrBytesPath, mode: Literal["r", "a", "w", "x"] = "r", fileobj: _Fileobj | None = None, format: int | None = None, @@ -161,11 +160,11 @@ class TarFile: copybufsize: int | None = None, # undocumented stream: bool = False, ) -> None: ... - @overload def __init__( self, fileobj: _Fileobj, + *, name: StrOrBytesPath | None = None, mode: Literal["r", "a", "w", "x"] = "r", format: int | None = None, @@ -197,11 +196,10 @@ class TarFile: errorlevel: int | None = None, copybufsize: int | None = None, # undocumented ) -> None: ... - @overload def __init__( # noqa: F811 self, - name: StrOrBytesPath | None, + name: StrOrBytesPath, mode: Literal["r", "a", "w", "x"] = "r", fileobj: _Fileobj | None = None, format: int | None = None, @@ -215,10 +213,10 @@ class TarFile: errorlevel: int | None = None, copybufsize: int | None = None, # undocumented ) -> None: ... - def __init__( self, fileobj: _Fileobj, + *, name: StrOrBytesPath | None = None, mode: Literal["r", "a", "w", "x"] = "r", format: int | None = None, From f3f21dde7f5a05fc9f480a7bdc73df74c0aa1465 Mon Sep 17 00:00:00 2001 From: Alexeev Bronislav Date: Tue, 27 May 2025 19:49:46 +0700 Subject: [PATCH 04/36] fix None/None case for other methods --- stdlib/tarfile.pyi | 256 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 256 insertions(+) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index cbf424c47c5c..8e1bf8b2ce36 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -257,6 +257,44 @@ class TarFile: ) -> Self: ... @overload @classmethod + def open( + cls, + name: StrOrBytesPath, + mode: Literal["r", "r:*", "r:", "r:gz", "r:bz2", "r:xz"] = "r", + 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 = ..., + ) -> Self: ... + @overload + @classmethod + def open( + cls, + fileobj: _Fileobj, + *, + name: StrOrBytesPath | None = None, + mode: Literal["r", "r:*", "r:", "r:gz", "r:bz2", "r:xz"] = "r", + 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 = ..., + ) -> Self: ... + @overload + @classmethod def open( cls, name: StrOrBytesPath | None, @@ -489,6 +527,7 @@ class TarFile: errorlevel: int | None = ..., compresslevel: int = 9, ) -> Self: ... + @overload @classmethod def taropen( cls, @@ -508,6 +547,42 @@ class TarFile: ) -> Self: ... @overload @classmethod + def taropen( + cls, + name: StrOrBytesPath, + 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 = ..., + ) -> Self: ... + @overload + @classmethod + def taropen( + cls, + fileobj: _Fileobj, + *, + name: StrOrBytesPath | None, + mode: Literal["r", "a", "w", "x"] = "r", + 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 = ..., + ) -> Self: ... + @overload + @classmethod def gzopen( cls, name: StrOrBytesPath | None, @@ -544,6 +619,78 @@ class TarFile: ) -> Self: ... @overload @classmethod + def gzopen( + cls, + fileobj: _GzipReadableFileobj, + *, + name: StrOrBytesPath | None, + mode: Literal["r"] = "r", + compresslevel: int = 9, + 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 gzopen( + cls, + name: StrOrBytesPath, + mode: Literal["w", "x"], + fileobj: _GzipWritableFileobj | None = None, + compresslevel: int = 9, + *, + 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 gzopen( + cls, + name: StrOrBytesPath, + mode: Literal["r"] = "r", + fileobj: _GzipReadableFileobj | None = None, + compresslevel: int = 9, + *, + 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 gzopen( + cls, + fileobj: _GzipWritableFileobj, + *, + name: StrOrBytesPath | None, + mode: Literal["w", "x"], + compresslevel: int = 9, + 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 bz2open( cls, name: StrOrBytesPath | None, @@ -578,6 +725,79 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload + @classmethod + def bz2open( + cls, + name: StrOrBytesPath, + mode: Literal["w", "x"], + fileobj: _Bz2WritableFileobj | None = None, + compresslevel: int = 9, + *, + 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 bz2open( + cls, + fileobj: _Bz2ReadableFileobj, + *, + name: StrOrBytesPath | None, + mode: Literal["r"] = "r", + compresslevel: int = 9, + 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 bz2open( + cls, + fileobj: _Bz2WritableFileobj, + *, + name: StrOrBytesPath | None, + mode: Literal["w", "x"], + compresslevel: int = 9, + 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 bz2open( + cls, + name: StrOrBytesPath, + mode: Literal["r"] = "r", + fileobj: _Bz2ReadableFileobj | None = None, + compresslevel: int = 9, + *, + 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 xzopen( cls, @@ -595,6 +815,42 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload + @classmethod + def xzopen( + cls, + name: StrOrBytesPath, + mode: Literal["r", "w", "x"] = "r", + fileobj: IO[bytes] | None = None, + preset: int | 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 xzopen( + cls, + fileobj: IO[bytes], + *, + name: StrOrBytesPath | None, + mode: Literal["r", "w", "x"] = "r", + preset: int | 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 f0a44103e09447f29814b4c642938e105d693217 Mon Sep 17 00:00:00 2001 From: Alexeev Bronislav Date: Tue, 27 May 2025 19:52:13 +0700 Subject: [PATCH 05/36] add overload to `__init__` --- stdlib/tarfile.pyi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 8e1bf8b2ce36..91e6aca5688d 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -125,6 +125,7 @@ class TarFile: extraction_filter: _FilterFunction | None if sys.version_info >= (3, 13): stream: bool + @overload def __init__( self, name: StrOrBytesPath | None = None, @@ -180,6 +181,7 @@ class TarFile: stream: bool = False, ) -> None: ... else: + @overload def __init__( self, name: StrOrBytesPath | None = None, From 6f4f644ff93bc6823d0d77a8c93e9b64233d475a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 27 May 2025 12:53:59 +0000 Subject: [PATCH 06/36] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/tarfile.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 91e6aca5688d..9bd7ddc1f917 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -144,7 +144,7 @@ class TarFile: stream: bool = False, ) -> None: ... @overload - def __init__( # noqa: F811 + def __init__( self, name: StrOrBytesPath, mode: Literal["r", "a", "w", "x"] = "r", @@ -199,7 +199,7 @@ class TarFile: copybufsize: int | None = None, # undocumented ) -> None: ... @overload - def __init__( # noqa: F811 + def __init__( self, name: StrOrBytesPath, mode: Literal["r", "a", "w", "x"] = "r", From 1e03be9e6788411d52b531674af59558ddda4d8e Mon Sep 17 00:00:00 2001 From: Alexeev Bronislav Date: Tue, 27 May 2025 19:58:16 +0700 Subject: [PATCH 07/36] fix overrided init methods --- stdlib/tarfile.pyi | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 91e6aca5688d..ee401b9ab5ef 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -128,7 +128,7 @@ class TarFile: @overload def __init__( self, - name: StrOrBytesPath | None = None, + name: StrOrBytesPath, mode: Literal["r", "a", "w", "x"] = "r", fileobj: _Fileobj | None = None, format: int | None = None, @@ -140,13 +140,13 @@ class TarFile: pax_headers: Mapping[str, str] | None = None, debug: int | None = None, errorlevel: int | None = None, - copybufsize: int | None = None, # undocumented + copybufsize: int | None = None, stream: bool = False, ) -> None: ... @overload - def __init__( # noqa: F811 + def __init__( self, - name: StrOrBytesPath, + name: StrOrBytesPath | None = None, mode: Literal["r", "a", "w", "x"] = "r", fileobj: _Fileobj | None = None, format: int | None = None, @@ -158,7 +158,7 @@ class TarFile: pax_headers: Mapping[str, str] | None = None, debug: int | None = None, errorlevel: int | None = None, - copybufsize: int | None = None, # undocumented + copybufsize: int | None = None, stream: bool = False, ) -> None: ... @overload @@ -177,14 +177,14 @@ class TarFile: pax_headers: Mapping[str, str] | None = None, debug: int | None = None, errorlevel: int | None = None, - copybufsize: int | None = None, # undocumented + copybufsize: int | None = None, stream: bool = False, ) -> None: ... else: @overload - def __init__( + def __init__( # Специфичная версия self, - name: StrOrBytesPath | None = None, + name: StrOrBytesPath, mode: Literal["r", "a", "w", "x"] = "r", fileobj: _Fileobj | None = None, format: int | None = None, @@ -196,12 +196,12 @@ class TarFile: pax_headers: Mapping[str, str] | None = None, debug: int | None = None, errorlevel: int | None = None, - copybufsize: int | None = None, # undocumented + copybufsize: int | None = None, ) -> None: ... @overload - def __init__( # noqa: F811 + def __init__( # Общая версия self, - name: StrOrBytesPath, + name: StrOrBytesPath | None = None, mode: Literal["r", "a", "w", "x"] = "r", fileobj: _Fileobj | None = None, format: int | None = None, @@ -213,9 +213,9 @@ class TarFile: pax_headers: Mapping[str, str] | None = None, debug: int | None = None, errorlevel: int | None = None, - copybufsize: int | None = None, # undocumented + copybufsize: int | None = None, ) -> None: ... - def __init__( + def __init__( # Реализация с fileobj как позиционным аргументом self, fileobj: _Fileobj, *, @@ -230,7 +230,7 @@ class TarFile: pax_headers: Mapping[str, str] | None = None, debug: int | None = None, errorlevel: int | None = None, - copybufsize: int | None = None, # undocumented + copybufsize: int | None = None, ) -> None: ... def __enter__(self) -> Self: ... From 0ec9a85e09c61b93eefd0044809e564c9d947821 Mon Sep 17 00:00:00 2001 From: Alexeev Bronislav Date: Tue, 27 May 2025 20:02:36 +0700 Subject: [PATCH 08/36] fix syntax error in __init__ methods --- stdlib/tarfile.pyi | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 27219d7943f8..d9353c12214d 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -128,27 +128,6 @@ class TarFile: @overload def __init__( self, -<<<<<<< HEAD -======= - name: StrOrBytesPath | None = None, - mode: Literal["r", "a", "w", "x"] = "r", - fileobj: _Fileobj | None = None, - format: int | None = None, - tarinfo: type[TarInfo] | None = None, - dereference: bool | None = None, - ignore_zeros: bool | None = None, - encoding: str | None = None, - errors: str = "surrogateescape", - pax_headers: Mapping[str, str] | None = None, - debug: int | None = None, - errorlevel: int | None = None, - copybufsize: int | None = None, # undocumented - stream: bool = False, - ) -> None: ... - @overload - def __init__( - self, ->>>>>>> 6f4f644ff93bc6823d0d77a8c93e9b64233d475a name: StrOrBytesPath, mode: Literal["r", "a", "w", "x"] = "r", fileobj: _Fileobj | None = None, From a7a5e8d4b04f0e112c0ca682bc1c8b26dc712c1d Mon Sep 17 00:00:00 2001 From: Alexeev Bronislav Date: Tue, 27 May 2025 20:09:33 +0700 Subject: [PATCH 09/36] fix errors in overrided init methods --- stdlib/tarfile.pyi | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index d9353c12214d..383f68baad14 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -201,9 +201,10 @@ class TarFile: @overload def __init__( self, + fileobj: _Fileobj, + *, name: StrOrBytesPath | None = None, mode: Literal["r", "a", "w", "x"] = "r", - fileobj: _Fileobj | None = None, format: int | None = None, tarinfo: type[TarInfo] | None = None, dereference: bool | None = None, @@ -215,12 +216,12 @@ class TarFile: errorlevel: int | None = None, copybufsize: int | None = None, ) -> None: ... + @overload def __init__( self, - fileobj: _Fileobj, - *, name: StrOrBytesPath | None = None, mode: Literal["r", "a", "w", "x"] = "r", + fileobj: _Fileobj | None = None, format: int | None = None, tarinfo: type[TarInfo] | None = None, dereference: bool | None = None, From 7eae058fbe750e7b53dc2686e073fa62fff4f026 Mon Sep 17 00:00:00 2001 From: Alexeev Bronislav Date: Tue, 27 May 2025 20:14:27 +0700 Subject: [PATCH 10/36] fix errors in overrided init methods for python<3.13 --- stdlib/tarfile.pyi | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 383f68baad14..f9c82ec0fa71 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -184,7 +184,7 @@ class TarFile: @overload def __init__( self, - name: StrOrBytesPath | None = None, + name: StrOrBytesPath, mode: Literal["r", "a", "w", "x"] = "r", fileobj: _Fileobj | None = None, format: int | None = None, @@ -196,15 +196,14 @@ class TarFile: pax_headers: Mapping[str, str] | None = None, debug: int | None = None, errorlevel: int | None = None, - copybufsize: int | None = None, # undocumented + copybufsize: int | None = None, ) -> None: ... @overload def __init__( self, - fileobj: _Fileobj, - *, name: StrOrBytesPath | None = None, mode: Literal["r", "a", "w", "x"] = "r", + fileobj: _Fileobj | None = None, format: int | None = None, tarinfo: type[TarInfo] | None = None, dereference: bool | None = None, @@ -219,9 +218,10 @@ class TarFile: @overload def __init__( self, + fileobj: _Fileobj, + *, name: StrOrBytesPath | None = None, mode: Literal["r", "a", "w", "x"] = "r", - fileobj: _Fileobj | None = None, format: int | None = None, tarinfo: type[TarInfo] | None = None, dereference: bool | None = None, From 69938e90e31c8a7c3fc671d97aab2173b545702e Mon Sep 17 00:00:00 2001 From: Alexeev Bronislav Date: Tue, 27 May 2025 20:31:55 +0700 Subject: [PATCH 11/36] work with overrired `open` methods in TarFile --- stdlib/tarfile.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index f9c82ec0fa71..05b545454599 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -243,7 +243,7 @@ class TarFile: @classmethod def open( cls, - name: StrOrBytesPath | None = None, + name: StrOrBytesPath, mode: Literal["r", "r:*", "r:", "r:gz", "r:bz2", "r:xz"] = "r", fileobj: _Fileobj | None = None, bufsize: int = 10240, @@ -262,7 +262,7 @@ class TarFile: @classmethod def open( cls, - name: StrOrBytesPath, + name: StrOrBytesPath | None = None, mode: Literal["r", "r:*", "r:", "r:gz", "r:bz2", "r:xz"] = "r", fileobj: _Fileobj | None = None, bufsize: int = 10240, From 5e4f00bb89b044e7c557bb9957ffc2e4190e4d45 Mon Sep 17 00:00:00 2001 From: Alexeev Bronislav Date: Tue, 27 May 2025 20:39:20 +0700 Subject: [PATCH 12/36] fix stubtest errors for TarFile overrided methods --- stdlib/tarfile.pyi | 54 +++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 05b545454599..ab4e6d34a328 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -534,7 +534,7 @@ class TarFile: @classmethod def taropen( cls, - name: StrOrBytesPath | None, + name: StrOrBytesPath, mode: Literal["r", "a", "w", "x"] = "r", fileobj: _Fileobj | None = None, *, @@ -552,7 +552,7 @@ class TarFile: @classmethod def taropen( cls, - name: StrOrBytesPath, + name: StrOrBytesPath | None, mode: Literal["r", "a", "w", "x"] = "r", fileobj: _Fileobj | None = None, *, @@ -588,7 +588,7 @@ class TarFile: @classmethod def gzopen( cls, - name: StrOrBytesPath | None, + name: StrOrBytesPath, mode: Literal["r"] = "r", fileobj: _GzipReadableFileobj | None = None, compresslevel: int = 9, @@ -606,7 +606,7 @@ class TarFile: @classmethod def gzopen( cls, - name: StrOrBytesPath | None, + name: StrOrBytesPath, mode: Literal["w", "x"], fileobj: _GzipWritableFileobj | None = None, compresslevel: int = 9, @@ -624,11 +624,11 @@ class TarFile: @classmethod def gzopen( cls, - fileobj: _GzipReadableFileobj, - *, name: StrOrBytesPath | None, mode: Literal["r"] = "r", + fileobj: _GzipReadableFileobj | None = None, compresslevel: int = 9, + *, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., dereference: bool | None = ..., @@ -642,7 +642,7 @@ class TarFile: @classmethod def gzopen( cls, - name: StrOrBytesPath, + name: StrOrBytesPath | None, mode: Literal["w", "x"], fileobj: _GzipWritableFileobj | None = None, compresslevel: int = 9, @@ -660,11 +660,11 @@ class TarFile: @classmethod def gzopen( cls, - name: StrOrBytesPath, + fileobj: _GzipReadableFileobj, + *, + name: StrOrBytesPath | None, mode: Literal["r"] = "r", - fileobj: _GzipReadableFileobj | None = None, compresslevel: int = 9, - *, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., dereference: bool | None = ..., @@ -696,9 +696,9 @@ class TarFile: @classmethod def bz2open( cls, - name: StrOrBytesPath | None, - mode: Literal["w", "x"], - fileobj: _Bz2WritableFileobj | None = None, + name: StrOrBytesPath, + mode: Literal["r"] = "r", + fileobj: _Bz2ReadableFileobj | None = None, compresslevel: int = 9, *, format: int | None = ..., @@ -714,9 +714,9 @@ class TarFile: @classmethod def bz2open( cls, - name: StrOrBytesPath | None, - mode: Literal["r"] = "r", - fileobj: _Bz2ReadableFileobj | None = None, + name: StrOrBytesPath, + mode: Literal["w", "x"], + fileobj: _Bz2WritableFileobj | None = None, compresslevel: int = 9, *, format: int | None = ..., @@ -732,7 +732,7 @@ class TarFile: @classmethod def bz2open( cls, - name: StrOrBytesPath, + name: StrOrBytesPath | None, mode: Literal["w", "x"], fileobj: _Bz2WritableFileobj | None = None, compresslevel: int = 9, @@ -750,11 +750,11 @@ class TarFile: @classmethod def bz2open( cls, - fileobj: _Bz2ReadableFileobj, - *, name: StrOrBytesPath | None, mode: Literal["r"] = "r", + fileobj: _Bz2ReadableFileobj | None = None, compresslevel: int = 9, + *, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., dereference: bool | None = ..., @@ -768,10 +768,10 @@ class TarFile: @classmethod def bz2open( cls, - fileobj: _Bz2WritableFileobj, + fileobj: _Bz2ReadableFileobj, *, name: StrOrBytesPath | None, - mode: Literal["w", "x"], + mode: Literal["r"] = "r", compresslevel: int = 9, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., @@ -786,11 +786,11 @@ class TarFile: @classmethod def bz2open( cls, - name: StrOrBytesPath, - mode: Literal["r"] = "r", - fileobj: _Bz2ReadableFileobj | None = None, - compresslevel: int = 9, + fileobj: _Bz2WritableFileobj, *, + name: StrOrBytesPath | None, + mode: Literal["w", "x"], + compresslevel: int = 9, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., dereference: bool | None = ..., @@ -804,7 +804,7 @@ class TarFile: @classmethod def xzopen( cls, - name: StrOrBytesPath | None, + name: StrOrBytesPath, mode: Literal["r", "w", "x"] = "r", fileobj: IO[bytes] | None = None, preset: int | None = None, @@ -822,7 +822,7 @@ class TarFile: @classmethod def xzopen( cls, - name: StrOrBytesPath, + name: StrOrBytesPath | None, mode: Literal["r", "w", "x"] = "r", fileobj: IO[bytes] | None = None, preset: int | None = None, From 5f3c8207092755be4c7bdef107324ef13864c4d3 Mon Sep 17 00:00:00 2001 From: Alexeev Bronislav Date: Tue, 27 May 2025 20:59:40 +0700 Subject: [PATCH 13/36] add info about TarFile in allowlists --- stdlib/@tests/stubtest_allowlists/common.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stdlib/@tests/stubtest_allowlists/common.txt b/stdlib/@tests/stubtest_allowlists/common.txt index a036c227f118..c9309388d109 100644 --- a/stdlib/@tests/stubtest_allowlists/common.txt +++ b/stdlib/@tests/stubtest_allowlists/common.txt @@ -548,3 +548,5 @@ xml.etree.cElementTree.XMLParser.__init__ # Defined in C so has general signatu # These would ideally be special-cased by type checkers; see https://github.com/python/mypy/issues/2220 xml.etree.ElementTree.Element.__iter__ xml.etree.cElementTree.Element.__iter__ + +tarfile.TarFile.open # Always overridden for fix open(name=None, fileobj=None) From d47a5daff426adfdb7fda37ee8cbcc72abafdeb1 Mon Sep 17 00:00:00 2001 From: Alexeev Bronislav Date: Tue, 27 May 2025 21:01:11 +0700 Subject: [PATCH 14/36] add info about TarFile in allowlists --- stdlib/@tests/stubtest_allowlists/common.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/stdlib/@tests/stubtest_allowlists/common.txt b/stdlib/@tests/stubtest_allowlists/common.txt index c9309388d109..d4b731eccdb4 100644 --- a/stdlib/@tests/stubtest_allowlists/common.txt +++ b/stdlib/@tests/stubtest_allowlists/common.txt @@ -550,3 +550,4 @@ xml.etree.ElementTree.Element.__iter__ xml.etree.cElementTree.Element.__iter__ tarfile.TarFile.open # Always overridden for fix open(name=None, fileobj=None) +tarfile.open # Overridden by TarFile.open From 51b46c9e68b6b2b3bfb8844634e4c99824815aee Mon Sep 17 00:00:00 2001 From: Alexeev Bronislav Date: Tue, 27 May 2025 21:03:34 +0700 Subject: [PATCH 15/36] fix info about TarFile in allowlists --- stdlib/@tests/stubtest_allowlists/common.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/stdlib/@tests/stubtest_allowlists/common.txt b/stdlib/@tests/stubtest_allowlists/common.txt index d4b731eccdb4..27ace812d398 100644 --- a/stdlib/@tests/stubtest_allowlists/common.txt +++ b/stdlib/@tests/stubtest_allowlists/common.txt @@ -549,5 +549,4 @@ xml.etree.cElementTree.XMLParser.__init__ # Defined in C so has general signatu xml.etree.ElementTree.Element.__iter__ xml.etree.cElementTree.Element.__iter__ -tarfile.TarFile.open # Always overridden for fix open(name=None, fileobj=None) tarfile.open # Overridden by TarFile.open From 9f28a91a230cc481f8dc2c1abf660ab578ee0552 Mon Sep 17 00:00:00 2001 From: Alexeev Bronislav Date: Sat, 5 Jul 2025 02:24:59 +0700 Subject: [PATCH 16/36] fix overloading for tarfile --- stdlib/tarfile.pyi | 294 +++++++++++++++++++++++++++++---------------- 1 file changed, 189 insertions(+), 105 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index ab4e6d34a328..0eb39aa46be5 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -2,7 +2,7 @@ import bz2 import io 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 builtins import list as _list from collections.abc import Callable, Iterable, Iterator, Mapping from gzip import _ReadableFileobj as _GzipReadableFileobj, _WritableFileobj as _GzipWritableFileobj from types import TracebackType @@ -48,9 +48,6 @@ class _Fileobj(Protocol): def tell(self) -> int: ... def seek(self, pos: int, /) -> object: ... def close(self) -> object: ... - # Optional fields: - # name: str | bytes - # mode: Literal["rb", "r+b", "wb", "xb"] class _Bz2ReadableFileobj(bz2._ReadableFileobj): def close(self) -> object: ... @@ -58,7 +55,6 @@ class _Bz2ReadableFileobj(bz2._ReadableFileobj): class _Bz2WritableFileobj(bz2._WritableFileobj): def close(self) -> object: ... -# tar constants NUL: bytes BLOCKSIZE: int RECORDSIZE: int @@ -92,8 +88,6 @@ GNU_FORMAT: int PAX_FORMAT: int DEFAULT_FORMAT: int -# tarfile constants - SUPPORTED_TYPES: tuple[bytes, ...] REGULAR_TYPES: tuple[bytes, ...] GNU_TYPES: tuple[bytes, ...] @@ -121,8 +115,9 @@ class TarFile: pax_headers: Mapping[str, str] | None debug: int | None errorlevel: int | None - offset: int # undocumented + offset: int extraction_filter: _FilterFunction | None + if sys.version_info >= (3, 13): stream: bool @overload @@ -144,24 +139,6 @@ class TarFile: stream: bool = False, ) -> None: ... @overload - def __init__( - self, - name: StrOrBytesPath | None = None, - mode: Literal["r", "a", "w", "x"] = "r", - fileobj: _Fileobj | None = None, - format: int | None = None, - tarinfo: type[TarInfo] | None = None, - dereference: bool | None = None, - ignore_zeros: bool | None = None, - encoding: str | None = None, - errors: str = "surrogateescape", - pax_headers: Mapping[str, str] | None = None, - debug: int | None = None, - errorlevel: int | None = None, - copybufsize: int | None = None, - stream: bool = False, - ) -> None: ... - @overload def __init__( self, fileobj: _Fileobj, @@ -199,23 +176,6 @@ class TarFile: copybufsize: int | None = None, ) -> None: ... @overload - def __init__( - self, - name: StrOrBytesPath | None = None, - mode: Literal["r", "a", "w", "x"] = "r", - fileobj: _Fileobj | None = None, - format: int | None = None, - tarinfo: type[TarInfo] | None = None, - dereference: bool | None = None, - ignore_zeros: bool | None = None, - encoding: str | None = None, - errors: str = "surrogateescape", - pax_headers: Mapping[str, str] | None = None, - debug: int | None = None, - errorlevel: int | None = None, - copybufsize: int | None = None, - ) -> None: ... - @overload def __init__( self, fileobj: _Fileobj, @@ -239,6 +199,7 @@ class TarFile: self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> None: ... def __iter__(self) -> Iterator[TarInfo]: ... + @overload @classmethod def open( @@ -262,11 +223,11 @@ class TarFile: @classmethod def open( cls, + fileobj: _Fileobj, + *, name: StrOrBytesPath | None = None, mode: Literal["r", "r:*", "r:", "r:gz", "r:bz2", "r:xz"] = "r", - fileobj: _Fileobj | None = None, bufsize: int = 10240, - *, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., dereference: bool | None = ..., @@ -281,8 +242,8 @@ class TarFile: @classmethod def open( cls, - fileobj: _Fileobj, *, + fileobj: _Fileobj, name: StrOrBytesPath | None = None, mode: Literal["r", "r:*", "r:", "r:gz", "r:bz2", "r:xz"] = "r", bufsize: int = 10240, @@ -296,11 +257,12 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload @classmethod def open( cls, - name: StrOrBytesPath | None, + name: StrOrBytesPath, mode: Literal["x", "x:", "a", "a:", "w", "w:", "w:tar"], fileobj: _Fileobj | None = None, bufsize: int = 10240, @@ -319,10 +281,29 @@ class TarFile: @classmethod def open( cls, + fileobj: _Fileobj, + *, name: StrOrBytesPath | None = None, + mode: Literal["x", "x:", "a", "a:", "w", "w:", "w:tar"], + 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 = ..., + ) -> Self: ... + @overload + @classmethod + def open( + cls, *, + fileobj: _Fileobj, + name: StrOrBytesPath | None = None, mode: Literal["x", "x:", "a", "a:", "w", "w:", "w:tar"], - fileobj: _Fileobj | None = None, bufsize: int = 10240, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., @@ -334,11 +315,12 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload @classmethod def open( cls, - name: StrOrBytesPath | None, + name: StrOrBytesPath, mode: Literal["x:gz", "x:bz2", "w:gz", "w:bz2"], fileobj: _Fileobj | None = None, bufsize: int = 10240, @@ -358,10 +340,30 @@ class TarFile: @classmethod def open( cls, + fileobj: _Fileobj, + *, name: StrOrBytesPath | None = None, + mode: Literal["x:gz", "x:bz2", "w:gz", "w:bz2"], + 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 = ..., + compresslevel: int = 9, + ) -> Self: ... + @overload + @classmethod + def open( + cls, *, + fileobj: _Fileobj, + name: StrOrBytesPath | None = None, mode: Literal["x:gz", "x:bz2", "w:gz", "w:bz2"], - fileobj: _Fileobj | None = None, bufsize: int = 10240, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., @@ -374,11 +376,12 @@ class TarFile: errorlevel: int | None = ..., compresslevel: int = 9, ) -> Self: ... + @overload @classmethod def open( cls, - name: StrOrBytesPath | None, + name: StrOrBytesPath, mode: Literal["x:xz", "w:xz"], fileobj: _Fileobj | None = None, bufsize: int = 10240, @@ -398,10 +401,30 @@ class TarFile: @classmethod def open( cls, + fileobj: _Fileobj, + *, name: StrOrBytesPath | None = None, + mode: Literal["x:xz", "w:xz"], + 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 = ..., + preset: Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | None = ..., + ) -> Self: ... + @overload + @classmethod + def open( + cls, *, + fileobj: _Fileobj, + name: StrOrBytesPath | None = None, mode: Literal["x:xz", "w:xz"], - fileobj: _Fileobj | None = None, bufsize: int = 10240, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., @@ -414,11 +437,12 @@ class TarFile: errorlevel: int | None = ..., preset: Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | None = ..., ) -> Self: ... + @overload @classmethod def open( cls, - name: StrOrBytesPath | ReadableBuffer | None, + name: StrOrBytesPath | ReadableBuffer, mode: Literal["r|*", "r|", "r|gz", "r|bz2", "r|xz"], fileobj: _Fileobj | None = None, bufsize: int = 10240, @@ -437,10 +461,29 @@ class TarFile: @classmethod def open( cls, + fileobj: _Fileobj, + *, name: StrOrBytesPath | ReadableBuffer | None = None, + mode: Literal["r|*", "r|", "r|gz", "r|bz2", "r|xz"], + 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 = ..., + ) -> Self: ... + @overload + @classmethod + def open( + cls, *, + fileobj: _Fileobj, + name: StrOrBytesPath | ReadableBuffer | None = None, mode: Literal["r|*", "r|", "r|gz", "r|bz2", "r|xz"], - fileobj: _Fileobj | None = None, bufsize: int = 10240, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., @@ -452,11 +495,12 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload @classmethod def open( cls, - name: StrOrBytesPath | WriteableBuffer | None, + name: StrOrBytesPath | WriteableBuffer, mode: Literal["w|", "w|xz"], fileobj: _Fileobj | None = None, bufsize: int = 10240, @@ -475,10 +519,29 @@ class TarFile: @classmethod def open( cls, + fileobj: _Fileobj, + *, name: StrOrBytesPath | WriteableBuffer | None = None, + mode: Literal["w|", "w|xz"], + 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 = ..., + ) -> Self: ... + @overload + @classmethod + def open( + cls, *, + fileobj: _Fileobj, + name: StrOrBytesPath | WriteableBuffer | None = None, mode: Literal["w|", "w|xz"], - fileobj: _Fileobj | None = None, bufsize: int = 10240, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., @@ -490,11 +553,12 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload @classmethod def open( cls, - name: StrOrBytesPath | WriteableBuffer | None, + name: StrOrBytesPath | WriteableBuffer, mode: Literal["w|gz", "w|bz2"], fileobj: _Fileobj | None = None, bufsize: int = 10240, @@ -514,10 +578,30 @@ class TarFile: @classmethod def open( cls, + fileobj: _Fileobj, + *, name: StrOrBytesPath | WriteableBuffer | None = None, + mode: Literal["w|gz", "w|bz2"], + 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 = ..., + compresslevel: int = 9, + ) -> Self: ... + @overload + @classmethod + def open( + cls, *, + fileobj: _Fileobj, + name: StrOrBytesPath | WriteableBuffer | None = None, mode: Literal["w|gz", "w|bz2"], - fileobj: _Fileobj | None = None, bufsize: int = 10240, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., @@ -530,6 +614,7 @@ class TarFile: errorlevel: int | None = ..., compresslevel: int = 9, ) -> Self: ... + @overload @classmethod def taropen( @@ -552,10 +637,10 @@ class TarFile: @classmethod def taropen( cls, - name: StrOrBytesPath | None, - mode: Literal["r", "a", "w", "x"] = "r", - fileobj: _Fileobj | None = None, + fileobj: _Fileobj, *, + name: StrOrBytesPath | None = None, + mode: Literal["r", "a", "w", "x"] = "r", compresslevel: int = ..., format: int | None = ..., tarinfo: type[TarInfo] | None = ..., @@ -570,9 +655,9 @@ class TarFile: @classmethod def taropen( cls, - fileobj: _Fileobj, *, - name: StrOrBytesPath | None, + fileobj: _Fileobj, + name: StrOrBytesPath | None = None, mode: Literal["r", "a", "w", "x"] = "r", compresslevel: int = ..., format: int | None = ..., @@ -584,6 +669,7 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload @classmethod def gzopen( @@ -624,11 +710,11 @@ class TarFile: @classmethod def gzopen( cls, - name: StrOrBytesPath | None, + fileobj: _GzipReadableFileobj, + *, + name: StrOrBytesPath | None = None, mode: Literal["r"] = "r", - fileobj: _GzipReadableFileobj | None = None, compresslevel: int = 9, - *, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., dereference: bool | None = ..., @@ -642,11 +728,11 @@ class TarFile: @classmethod def gzopen( cls, - name: StrOrBytesPath | None, + fileobj: _GzipWritableFileobj, + *, + name: StrOrBytesPath | None = None, mode: Literal["w", "x"], - fileobj: _GzipWritableFileobj | None = None, compresslevel: int = 9, - *, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., dereference: bool | None = ..., @@ -660,9 +746,9 @@ class TarFile: @classmethod def gzopen( cls, - fileobj: _GzipReadableFileobj, *, - name: StrOrBytesPath | None, + fileobj: _GzipReadableFileobj, + name: StrOrBytesPath | None = None, mode: Literal["r"] = "r", compresslevel: int = 9, format: int | None = ..., @@ -678,9 +764,9 @@ class TarFile: @classmethod def gzopen( cls, - fileobj: _GzipWritableFileobj, *, - name: StrOrBytesPath | None, + fileobj: _GzipWritableFileobj, + name: StrOrBytesPath | None = None, mode: Literal["w", "x"], compresslevel: int = 9, format: int | None = ..., @@ -692,6 +778,7 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload @classmethod def bz2open( @@ -732,11 +819,11 @@ class TarFile: @classmethod def bz2open( cls, - name: StrOrBytesPath | None, - mode: Literal["w", "x"], - fileobj: _Bz2WritableFileobj | None = None, - compresslevel: int = 9, + fileobj: _Bz2ReadableFileobj, *, + name: StrOrBytesPath | None = None, + mode: Literal["r"] = "r", + compresslevel: int = 9, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., dereference: bool | None = ..., @@ -750,11 +837,11 @@ class TarFile: @classmethod def bz2open( cls, - name: StrOrBytesPath | None, - mode: Literal["r"] = "r", - fileobj: _Bz2ReadableFileobj | None = None, - compresslevel: int = 9, + fileobj: _Bz2WritableFileobj, *, + name: StrOrBytesPath | None = None, + mode: Literal["w", "x"], + compresslevel: int = 9, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., dereference: bool | None = ..., @@ -768,9 +855,9 @@ class TarFile: @classmethod def bz2open( cls, - fileobj: _Bz2ReadableFileobj, *, - name: StrOrBytesPath | None, + fileobj: _Bz2ReadableFileobj, + name: StrOrBytesPath | None = None, mode: Literal["r"] = "r", compresslevel: int = 9, format: int | None = ..., @@ -786,9 +873,9 @@ class TarFile: @classmethod def bz2open( cls, - fileobj: _Bz2WritableFileobj, *, - name: StrOrBytesPath | None, + fileobj: _Bz2WritableFileobj, + name: StrOrBytesPath | None = None, mode: Literal["w", "x"], compresslevel: int = 9, format: int | None = ..., @@ -800,6 +887,7 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload @classmethod def xzopen( @@ -822,11 +910,11 @@ class TarFile: @classmethod def xzopen( cls, - name: StrOrBytesPath | None, + fileobj: IO[bytes], + *, + name: StrOrBytesPath | None = None, mode: Literal["r", "w", "x"] = "r", - fileobj: IO[bytes] | None = None, preset: int | None = None, - *, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., dereference: bool | None = ..., @@ -840,9 +928,9 @@ class TarFile: @classmethod def xzopen( cls, - fileobj: IO[bytes], *, - name: StrOrBytesPath | None, + fileobj: IO[bytes], + name: StrOrBytesPath | None = None, mode: Literal["r", "w", "x"] = "r", preset: int | None = None, format: int | None = ..., @@ -854,13 +942,12 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + def getmember(self, name: str) -> TarInfo: ... def getmembers(self) -> _list[TarInfo]: ... def getnames(self) -> _list[str]: ... def list(self, verbose: bool = True, *, members: _list[TarInfo] | None = None) -> None: ... def next(self) -> TarInfo | None: ... - # Calling this method without `filter` is deprecated, but it may be set either on the class or in an - # individual call, so we can't mark it as @deprecated here. def extractall( self, path: StrOrBytesPath = ".", @@ -869,7 +956,6 @@ class TarFile: numeric_owner: bool = False, filter: _TarfileFilter | None = ..., ) -> None: ... - # Same situation as for `extractall`. def extract( self, member: str | TarInfo, @@ -881,17 +967,17 @@ class TarFile: ) -> None: ... def _extract_member( self, tarinfo: TarInfo, targetpath: str, set_attrs: bool = True, numeric_owner: bool = False - ) -> None: ... # undocumented + ) -> None: ... def extractfile(self, member: str | TarInfo) -> IO[bytes] | None: ... - def makedir(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented - def makefile(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented - def makeunknown(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented - def makefifo(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented - def makedev(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented - def makelink(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented - def chown(self, tarinfo: TarInfo, targetpath: StrOrBytesPath, numeric_owner: bool) -> None: ... # undocumented - def chmod(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented - def utime(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented + def makedir(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... + def makefile(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... + def makeunknown(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... + def makefifo(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... + def makedev(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... + def makelink(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... + def chown(self, tarinfo: TarInfo, targetpath: StrOrBytesPath, numeric_owner: bool) -> None: ... + def chmod(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... + def utime(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... def add( self, name: StrPath, @@ -918,8 +1004,6 @@ class ExtractError(TarError): ... class HeaderError(TarError): ... class FilterError(TarError): - # This attribute is only set directly on the subclasses, but the documentation guarantees - # that it is always present on FilterError. tarinfo: TarInfo class AbsolutePathError(FilterError): From 81656dc60ee1c3ff775983672d4d89b3cf1a123f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 4 Jul 2025 19:29:31 +0000 Subject: [PATCH 17/36] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/tarfile.pyi | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 0e5081264f13..4a82757712ea 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -201,7 +201,6 @@ class TarFile: self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> None: ... def __iter__(self) -> Iterator[TarInfo]: ... - @overload @classmethod def open( @@ -259,7 +258,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - @overload @classmethod def open( @@ -317,7 +315,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - @overload @classmethod def open( @@ -378,7 +375,6 @@ class TarFile: errorlevel: int | None = ..., compresslevel: int = 9, ) -> Self: ... - @overload @classmethod def open( @@ -439,7 +435,6 @@ class TarFile: errorlevel: int | None = ..., preset: Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | None = ..., ) -> Self: ... - @overload @classmethod def open( @@ -497,7 +492,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - @overload @classmethod def open( @@ -555,7 +549,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - @overload @classmethod def open( @@ -616,7 +609,6 @@ class TarFile: errorlevel: int | None = ..., compresslevel: int = 9, ) -> Self: ... - @overload @classmethod def taropen( @@ -671,7 +663,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - @overload @classmethod def gzopen( @@ -780,7 +771,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - @overload @classmethod def bz2open( @@ -889,7 +879,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - @overload @classmethod def xzopen( @@ -944,7 +933,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - def getmember(self, name: str) -> TarInfo: ... def getmembers(self) -> _list[TarInfo]: ... def getnames(self) -> _list[str]: ... From 04b0e6e25cdaf2488ffe44a3c09d7fd12348430e Mon Sep 17 00:00:00 2001 From: Alexeev Bronislav Date: Sat, 5 Jul 2025 02:31:34 +0700 Subject: [PATCH 18/36] fix overloading for TarFile --- stdlib/tarfile.pyi | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 0e5081264f13..0eb39aa46be5 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -38,8 +38,6 @@ if sys.version_info >= (3, 12): "AbsolutePathError", "LinkOutsideDestinationError", ] -if sys.version_info >= (3, 13): - __all__ += ["LinkFallbackError"] _FilterFunction: TypeAlias = Callable[[TarInfo, str], TarInfo | None] _TarfileFilter: TypeAlias = Literal["fully_trusted", "tar", "data"] | _FilterFunction @@ -968,28 +966,18 @@ class TarFile: filter: _TarfileFilter | None = ..., ) -> None: ... def _extract_member( - self, - tarinfo: TarInfo, - targetpath: str, - set_attrs: bool = True, - numeric_owner: bool = False, - *, - filter_function: _FilterFunction | None = None, - extraction_root: str | None = None, - ) -> None: ... # undocumented + self, tarinfo: TarInfo, targetpath: str, set_attrs: bool = True, numeric_owner: bool = False + ) -> None: ... def extractfile(self, member: str | TarInfo) -> IO[bytes] | None: ... - def makedir(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented - def makefile(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented - def makeunknown(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented - def makefifo(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented - def makedev(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented - def makelink(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented - def makelink_with_filter( - self, tarinfo: TarInfo, targetpath: StrOrBytesPath, filter_function: _FilterFunction, extraction_root: str - ) -> None: ... # undocumented - def chown(self, tarinfo: TarInfo, targetpath: StrOrBytesPath, numeric_owner: bool) -> None: ... # undocumented - def chmod(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented - def utime(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented + def makedir(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... + def makefile(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... + def makeunknown(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... + def makefifo(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... + def makedev(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... + def makelink(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... + def chown(self, tarinfo: TarInfo, targetpath: StrOrBytesPath, numeric_owner: bool) -> None: ... + def chmod(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... + def utime(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... def add( self, name: StrPath, @@ -1033,9 +1021,6 @@ class AbsoluteLinkError(FilterError): class LinkOutsideDestinationError(FilterError): def __init__(self, tarinfo: TarInfo, path: str) -> None: ... -class LinkFallbackError(FilterError): - def __init__(self, tarinfo: TarInfo, path: str) -> None: ... - def fully_trusted_filter(member: TarInfo, dest_path: str) -> TarInfo: ... def tar_filter(member: TarInfo, dest_path: str) -> TarInfo: ... def data_filter(member: TarInfo, dest_path: str) -> TarInfo: ... From 31e4037aeac63e12e4cc98229e71dca60063e8cb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 4 Jul 2025 19:35:23 +0000 Subject: [PATCH 19/36] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/tarfile.pyi | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 0c2f28453c40..70bf96b60f92 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -953,9 +953,7 @@ class TarFile: numeric_owner: bool = False, filter: _TarfileFilter | None = ..., ) -> None: ... - def _extract_member( - self, tarinfo: TarInfo, targetpath: str, set_attrs: bool = True, numeric_owner: bool = False - ) -> None: ... + def _extract_member(self, tarinfo: TarInfo, targetpath: str, set_attrs: bool = True, numeric_owner: bool = False) -> None: ... def extractfile(self, member: str | TarInfo) -> IO[bytes] | None: ... def makedir(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... def makefile(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... From ea4c76227347f0cbb4a3beacd6ba277957d78253 Mon Sep 17 00:00:00 2001 From: Alexeev Bronislav Date: Sat, 5 Jul 2025 02:35:48 +0700 Subject: [PATCH 20/36] fix overloading for TarFile --- stdlib/tarfile.pyi | 49 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 0c2f28453c40..0e5081264f13 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -38,6 +38,8 @@ if sys.version_info >= (3, 12): "AbsolutePathError", "LinkOutsideDestinationError", ] +if sys.version_info >= (3, 13): + __all__ += ["LinkFallbackError"] _FilterFunction: TypeAlias = Callable[[TarInfo, str], TarInfo | None] _TarfileFilter: TypeAlias = Literal["fully_trusted", "tar", "data"] | _FilterFunction @@ -199,6 +201,7 @@ class TarFile: self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> None: ... def __iter__(self) -> Iterator[TarInfo]: ... + @overload @classmethod def open( @@ -256,6 +259,7 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload @classmethod def open( @@ -313,6 +317,7 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload @classmethod def open( @@ -373,6 +378,7 @@ class TarFile: errorlevel: int | None = ..., compresslevel: int = 9, ) -> Self: ... + @overload @classmethod def open( @@ -433,6 +439,7 @@ class TarFile: errorlevel: int | None = ..., preset: Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | None = ..., ) -> Self: ... + @overload @classmethod def open( @@ -490,6 +497,7 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload @classmethod def open( @@ -547,6 +555,7 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload @classmethod def open( @@ -607,6 +616,7 @@ class TarFile: errorlevel: int | None = ..., compresslevel: int = 9, ) -> Self: ... + @overload @classmethod def taropen( @@ -661,6 +671,7 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload @classmethod def gzopen( @@ -769,6 +780,7 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload @classmethod def bz2open( @@ -877,6 +889,7 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload @classmethod def xzopen( @@ -931,6 +944,7 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + def getmember(self, name: str) -> TarInfo: ... def getmembers(self) -> _list[TarInfo]: ... def getnames(self) -> _list[str]: ... @@ -954,18 +968,28 @@ class TarFile: filter: _TarfileFilter | None = ..., ) -> None: ... def _extract_member( - self, tarinfo: TarInfo, targetpath: str, set_attrs: bool = True, numeric_owner: bool = False - ) -> None: ... + self, + tarinfo: TarInfo, + targetpath: str, + set_attrs: bool = True, + numeric_owner: bool = False, + *, + filter_function: _FilterFunction | None = None, + extraction_root: str | None = None, + ) -> None: ... # undocumented def extractfile(self, member: str | TarInfo) -> IO[bytes] | None: ... - def makedir(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... - def makefile(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... - def makeunknown(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... - def makefifo(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... - def makedev(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... - def makelink(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... - def chown(self, tarinfo: TarInfo, targetpath: StrOrBytesPath, numeric_owner: bool) -> None: ... - def chmod(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... - def utime(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... + def makedir(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented + def makefile(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented + def makeunknown(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented + def makefifo(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented + def makedev(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented + def makelink(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented + def makelink_with_filter( + self, tarinfo: TarInfo, targetpath: StrOrBytesPath, filter_function: _FilterFunction, extraction_root: str + ) -> None: ... # undocumented + def chown(self, tarinfo: TarInfo, targetpath: StrOrBytesPath, numeric_owner: bool) -> None: ... # undocumented + def chmod(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented + def utime(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented def add( self, name: StrPath, @@ -1009,6 +1033,9 @@ class AbsoluteLinkError(FilterError): class LinkOutsideDestinationError(FilterError): def __init__(self, tarinfo: TarInfo, path: str) -> None: ... +class LinkFallbackError(FilterError): + def __init__(self, tarinfo: TarInfo, path: str) -> None: ... + def fully_trusted_filter(member: TarInfo, dest_path: str) -> TarInfo: ... def tar_filter(member: TarInfo, dest_path: str) -> TarInfo: ... def data_filter(member: TarInfo, dest_path: str) -> TarInfo: ... From d815ec5e37f3dc5a7f968af8112b6f19ec96228c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 4 Jul 2025 19:38:44 +0000 Subject: [PATCH 21/36] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/tarfile.pyi | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index fa44e721ce3f..51a9bcd731a2 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -201,7 +201,6 @@ class TarFile: self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> None: ... def __iter__(self) -> Iterator[TarInfo]: ... - @overload @classmethod def open( @@ -259,7 +258,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - @overload @classmethod def open( @@ -317,7 +315,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - @overload @classmethod def open( @@ -378,7 +375,6 @@ class TarFile: errorlevel: int | None = ..., compresslevel: int = 9, ) -> Self: ... - @overload @classmethod def open( @@ -439,7 +435,6 @@ class TarFile: errorlevel: int | None = ..., preset: Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | None = ..., ) -> Self: ... - @overload @classmethod def open( @@ -497,7 +492,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - @overload @classmethod def open( @@ -555,7 +549,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - @overload @classmethod def open( @@ -616,7 +609,6 @@ class TarFile: errorlevel: int | None = ..., compresslevel: int = 9, ) -> Self: ... - @overload @classmethod def taropen( @@ -671,7 +663,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - @overload @classmethod def gzopen( @@ -780,7 +771,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - @overload @classmethod def bz2open( @@ -889,7 +879,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - @overload @classmethod def xzopen( @@ -944,7 +933,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - def getmember(self, name: str) -> TarInfo: ... def getmembers(self) -> _list[TarInfo]: ... def getnames(self) -> _list[str]: ... From 649d343adff4543d7c44be2626bb5e6158132a1b Mon Sep 17 00:00:00 2001 From: Alexeev Bronislav Date: Sat, 5 Jul 2025 02:50:02 +0700 Subject: [PATCH 22/36] fix stubtest errors for TarFile methods --- stdlib/tarfile.pyi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 51a9bcd731a2..9551fd38b24d 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -282,8 +282,8 @@ class TarFile: def open( cls, fileobj: _Fileobj, + name: StrOrBytesPath, *, - name: StrOrBytesPath | None = None, mode: Literal["x", "x:", "a", "a:", "w", "w:", "w:tar"], bufsize: int = 10240, format: int | None = ..., @@ -613,9 +613,9 @@ class TarFile: @classmethod def taropen( cls, + fileobj: _Fileobj, name: StrOrBytesPath, mode: Literal["r", "a", "w", "x"] = "r", - fileobj: _Fileobj | None = None, *, compresslevel: int = ..., format: int | None = ..., @@ -667,9 +667,9 @@ class TarFile: @classmethod def gzopen( cls, + fileobj: _GzipReadableFileobj, name: StrOrBytesPath, mode: Literal["r"] = "r", - fileobj: _GzipReadableFileobj | None = None, compresslevel: int = 9, *, format: int | None = ..., @@ -685,9 +685,9 @@ class TarFile: @classmethod def gzopen( cls, + fileobj: _GzipWritableFileobj, name: StrOrBytesPath, mode: Literal["w", "x"], - fileobj: _GzipWritableFileobj | None = None, compresslevel: int = 9, *, format: int | None = ..., From eaa1ed40f8e2675c0b8a9a8b7f110ab1ea7de04d Mon Sep 17 00:00:00 2001 From: Alexeev Bronislav Date: Sat, 5 Jul 2025 02:54:45 +0700 Subject: [PATCH 23/36] fix stubtest errors for TarFile methods --- stdlib/tarfile.pyi | 282 ++++++++++++++++----------------------------- 1 file changed, 102 insertions(+), 180 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 9551fd38b24d..ab4e6d34a328 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -2,7 +2,7 @@ import bz2 import io import sys from _typeshed import ReadableBuffer, StrOrBytesPath, StrPath, SupportsRead, WriteableBuffer -from builtins import list as _list +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 gzip import _ReadableFileobj as _GzipReadableFileobj, _WritableFileobj as _GzipWritableFileobj from types import TracebackType @@ -38,8 +38,6 @@ if sys.version_info >= (3, 12): "AbsolutePathError", "LinkOutsideDestinationError", ] -if sys.version_info >= (3, 13): - __all__ += ["LinkFallbackError"] _FilterFunction: TypeAlias = Callable[[TarInfo, str], TarInfo | None] _TarfileFilter: TypeAlias = Literal["fully_trusted", "tar", "data"] | _FilterFunction @@ -50,6 +48,9 @@ class _Fileobj(Protocol): def tell(self) -> int: ... def seek(self, pos: int, /) -> object: ... def close(self) -> object: ... + # Optional fields: + # name: str | bytes + # mode: Literal["rb", "r+b", "wb", "xb"] class _Bz2ReadableFileobj(bz2._ReadableFileobj): def close(self) -> object: ... @@ -57,6 +58,7 @@ class _Bz2ReadableFileobj(bz2._ReadableFileobj): class _Bz2WritableFileobj(bz2._WritableFileobj): def close(self) -> object: ... +# tar constants NUL: bytes BLOCKSIZE: int RECORDSIZE: int @@ -90,6 +92,8 @@ GNU_FORMAT: int PAX_FORMAT: int DEFAULT_FORMAT: int +# tarfile constants + SUPPORTED_TYPES: tuple[bytes, ...] REGULAR_TYPES: tuple[bytes, ...] GNU_TYPES: tuple[bytes, ...] @@ -117,9 +121,8 @@ class TarFile: pax_headers: Mapping[str, str] | None debug: int | None errorlevel: int | None - offset: int + offset: int # undocumented extraction_filter: _FilterFunction | None - if sys.version_info >= (3, 13): stream: bool @overload @@ -141,6 +144,24 @@ class TarFile: stream: bool = False, ) -> None: ... @overload + def __init__( + self, + name: StrOrBytesPath | None = None, + mode: Literal["r", "a", "w", "x"] = "r", + fileobj: _Fileobj | None = None, + format: int | None = None, + tarinfo: type[TarInfo] | None = None, + dereference: bool | None = None, + ignore_zeros: bool | None = None, + encoding: str | None = None, + errors: str = "surrogateescape", + pax_headers: Mapping[str, str] | None = None, + debug: int | None = None, + errorlevel: int | None = None, + copybufsize: int | None = None, + stream: bool = False, + ) -> None: ... + @overload def __init__( self, fileobj: _Fileobj, @@ -178,6 +199,23 @@ class TarFile: copybufsize: int | None = None, ) -> None: ... @overload + def __init__( + self, + name: StrOrBytesPath | None = None, + mode: Literal["r", "a", "w", "x"] = "r", + fileobj: _Fileobj | None = None, + format: int | None = None, + tarinfo: type[TarInfo] | None = None, + dereference: bool | None = None, + ignore_zeros: bool | None = None, + encoding: str | None = None, + errors: str = "surrogateescape", + pax_headers: Mapping[str, str] | None = None, + debug: int | None = None, + errorlevel: int | None = None, + copybufsize: int | None = None, + ) -> None: ... + @overload def __init__( self, fileobj: _Fileobj, @@ -224,11 +262,11 @@ class TarFile: @classmethod def open( cls, - fileobj: _Fileobj, - *, name: StrOrBytesPath | None = None, mode: Literal["r", "r:*", "r:", "r:gz", "r:bz2", "r:xz"] = "r", + fileobj: _Fileobj | None = None, bufsize: int = 10240, + *, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., dereference: bool | None = ..., @@ -243,8 +281,8 @@ class TarFile: @classmethod def open( cls, - *, fileobj: _Fileobj, + *, name: StrOrBytesPath | None = None, mode: Literal["r", "r:*", "r:", "r:gz", "r:bz2", "r:xz"] = "r", bufsize: int = 10240, @@ -262,7 +300,7 @@ class TarFile: @classmethod def open( cls, - name: StrOrBytesPath, + name: StrOrBytesPath | None, mode: Literal["x", "x:", "a", "a:", "w", "w:", "w:tar"], fileobj: _Fileobj | None = None, bufsize: int = 10240, @@ -281,29 +319,10 @@ class TarFile: @classmethod def open( cls, - fileobj: _Fileobj, - name: StrOrBytesPath, - *, - mode: Literal["x", "x:", "a", "a:", "w", "w:", "w:tar"], - 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 = ..., - ) -> Self: ... - @overload - @classmethod - def open( - cls, - *, - fileobj: _Fileobj, name: StrOrBytesPath | None = None, + *, mode: Literal["x", "x:", "a", "a:", "w", "w:", "w:tar"], + fileobj: _Fileobj | None = None, bufsize: int = 10240, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., @@ -319,7 +338,7 @@ class TarFile: @classmethod def open( cls, - name: StrOrBytesPath, + name: StrOrBytesPath | None, mode: Literal["x:gz", "x:bz2", "w:gz", "w:bz2"], fileobj: _Fileobj | None = None, bufsize: int = 10240, @@ -339,30 +358,10 @@ class TarFile: @classmethod def open( cls, - fileobj: _Fileobj, - *, name: StrOrBytesPath | None = None, - mode: Literal["x:gz", "x:bz2", "w:gz", "w:bz2"], - 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 = ..., - compresslevel: int = 9, - ) -> Self: ... - @overload - @classmethod - def open( - cls, *, - fileobj: _Fileobj, - name: StrOrBytesPath | None = None, mode: Literal["x:gz", "x:bz2", "w:gz", "w:bz2"], + fileobj: _Fileobj | None = None, bufsize: int = 10240, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., @@ -379,7 +378,7 @@ class TarFile: @classmethod def open( cls, - name: StrOrBytesPath, + name: StrOrBytesPath | None, mode: Literal["x:xz", "w:xz"], fileobj: _Fileobj | None = None, bufsize: int = 10240, @@ -399,30 +398,10 @@ class TarFile: @classmethod def open( cls, - fileobj: _Fileobj, - *, name: StrOrBytesPath | None = None, - mode: Literal["x:xz", "w:xz"], - 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 = ..., - preset: Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | None = ..., - ) -> Self: ... - @overload - @classmethod - def open( - cls, *, - fileobj: _Fileobj, - name: StrOrBytesPath | None = None, mode: Literal["x:xz", "w:xz"], + fileobj: _Fileobj | None = None, bufsize: int = 10240, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., @@ -439,7 +418,7 @@ class TarFile: @classmethod def open( cls, - name: StrOrBytesPath | ReadableBuffer, + name: StrOrBytesPath | ReadableBuffer | None, mode: Literal["r|*", "r|", "r|gz", "r|bz2", "r|xz"], fileobj: _Fileobj | None = None, bufsize: int = 10240, @@ -458,29 +437,10 @@ class TarFile: @classmethod def open( cls, - fileobj: _Fileobj, - *, name: StrOrBytesPath | ReadableBuffer | None = None, - mode: Literal["r|*", "r|", "r|gz", "r|bz2", "r|xz"], - 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 = ..., - ) -> Self: ... - @overload - @classmethod - def open( - cls, *, - fileobj: _Fileobj, - name: StrOrBytesPath | ReadableBuffer | None = None, mode: Literal["r|*", "r|", "r|gz", "r|bz2", "r|xz"], + fileobj: _Fileobj | None = None, bufsize: int = 10240, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., @@ -496,7 +456,7 @@ class TarFile: @classmethod def open( cls, - name: StrOrBytesPath | WriteableBuffer, + name: StrOrBytesPath | WriteableBuffer | None, mode: Literal["w|", "w|xz"], fileobj: _Fileobj | None = None, bufsize: int = 10240, @@ -515,29 +475,10 @@ class TarFile: @classmethod def open( cls, - fileobj: _Fileobj, - *, name: StrOrBytesPath | WriteableBuffer | None = None, - mode: Literal["w|", "w|xz"], - 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 = ..., - ) -> Self: ... - @overload - @classmethod - def open( - cls, *, - fileobj: _Fileobj, - name: StrOrBytesPath | WriteableBuffer | None = None, mode: Literal["w|", "w|xz"], + fileobj: _Fileobj | None = None, bufsize: int = 10240, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., @@ -553,7 +494,7 @@ class TarFile: @classmethod def open( cls, - name: StrOrBytesPath | WriteableBuffer, + name: StrOrBytesPath | WriteableBuffer | None, mode: Literal["w|gz", "w|bz2"], fileobj: _Fileobj | None = None, bufsize: int = 10240, @@ -573,30 +514,10 @@ class TarFile: @classmethod def open( cls, - fileobj: _Fileobj, - *, name: StrOrBytesPath | WriteableBuffer | None = None, - mode: Literal["w|gz", "w|bz2"], - 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 = ..., - compresslevel: int = 9, - ) -> Self: ... - @overload - @classmethod - def open( - cls, *, - fileobj: _Fileobj, - name: StrOrBytesPath | WriteableBuffer | None = None, mode: Literal["w|gz", "w|bz2"], + fileobj: _Fileobj | None = None, bufsize: int = 10240, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., @@ -613,9 +534,9 @@ class TarFile: @classmethod def taropen( cls, - fileobj: _Fileobj, name: StrOrBytesPath, mode: Literal["r", "a", "w", "x"] = "r", + fileobj: _Fileobj | None = None, *, compresslevel: int = ..., format: int | None = ..., @@ -631,10 +552,10 @@ class TarFile: @classmethod def taropen( cls, - fileobj: _Fileobj, - *, - name: StrOrBytesPath | None = None, + name: StrOrBytesPath | None, mode: Literal["r", "a", "w", "x"] = "r", + fileobj: _Fileobj | None = None, + *, compresslevel: int = ..., format: int | None = ..., tarinfo: type[TarInfo] | None = ..., @@ -649,9 +570,9 @@ class TarFile: @classmethod def taropen( cls, - *, fileobj: _Fileobj, - name: StrOrBytesPath | None = None, + *, + name: StrOrBytesPath | None, mode: Literal["r", "a", "w", "x"] = "r", compresslevel: int = ..., format: int | None = ..., @@ -667,9 +588,9 @@ class TarFile: @classmethod def gzopen( cls, - fileobj: _GzipReadableFileobj, name: StrOrBytesPath, mode: Literal["r"] = "r", + fileobj: _GzipReadableFileobj | None = None, compresslevel: int = 9, *, format: int | None = ..., @@ -685,9 +606,9 @@ class TarFile: @classmethod def gzopen( cls, - fileobj: _GzipWritableFileobj, name: StrOrBytesPath, mode: Literal["w", "x"], + fileobj: _GzipWritableFileobj | None = None, compresslevel: int = 9, *, format: int | None = ..., @@ -703,11 +624,11 @@ class TarFile: @classmethod def gzopen( cls, - fileobj: _GzipReadableFileobj, - *, - name: StrOrBytesPath | None = None, + name: StrOrBytesPath | None, mode: Literal["r"] = "r", + fileobj: _GzipReadableFileobj | None = None, compresslevel: int = 9, + *, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., dereference: bool | None = ..., @@ -721,11 +642,11 @@ class TarFile: @classmethod def gzopen( cls, - fileobj: _GzipWritableFileobj, - *, - name: StrOrBytesPath | None = None, + name: StrOrBytesPath | None, mode: Literal["w", "x"], + fileobj: _GzipWritableFileobj | None = None, compresslevel: int = 9, + *, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., dereference: bool | None = ..., @@ -739,9 +660,9 @@ class TarFile: @classmethod def gzopen( cls, - *, fileobj: _GzipReadableFileobj, - name: StrOrBytesPath | None = None, + *, + name: StrOrBytesPath | None, mode: Literal["r"] = "r", compresslevel: int = 9, format: int | None = ..., @@ -757,9 +678,9 @@ class TarFile: @classmethod def gzopen( cls, - *, fileobj: _GzipWritableFileobj, - name: StrOrBytesPath | None = None, + *, + name: StrOrBytesPath | None, mode: Literal["w", "x"], compresslevel: int = 9, format: int | None = ..., @@ -811,11 +732,11 @@ class TarFile: @classmethod def bz2open( cls, - fileobj: _Bz2ReadableFileobj, - *, - name: StrOrBytesPath | None = None, - mode: Literal["r"] = "r", + name: StrOrBytesPath | None, + mode: Literal["w", "x"], + fileobj: _Bz2WritableFileobj | None = None, compresslevel: int = 9, + *, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., dereference: bool | None = ..., @@ -829,11 +750,11 @@ class TarFile: @classmethod def bz2open( cls, - fileobj: _Bz2WritableFileobj, - *, - name: StrOrBytesPath | None = None, - mode: Literal["w", "x"], + name: StrOrBytesPath | None, + mode: Literal["r"] = "r", + fileobj: _Bz2ReadableFileobj | None = None, compresslevel: int = 9, + *, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., dereference: bool | None = ..., @@ -847,9 +768,9 @@ class TarFile: @classmethod def bz2open( cls, - *, fileobj: _Bz2ReadableFileobj, - name: StrOrBytesPath | None = None, + *, + name: StrOrBytesPath | None, mode: Literal["r"] = "r", compresslevel: int = 9, format: int | None = ..., @@ -865,9 +786,9 @@ class TarFile: @classmethod def bz2open( cls, - *, fileobj: _Bz2WritableFileobj, - name: StrOrBytesPath | None = None, + *, + name: StrOrBytesPath | None, mode: Literal["w", "x"], compresslevel: int = 9, format: int | None = ..., @@ -901,11 +822,11 @@ class TarFile: @classmethod def xzopen( cls, - fileobj: IO[bytes], - *, - name: StrOrBytesPath | None = None, + name: StrOrBytesPath | None, mode: Literal["r", "w", "x"] = "r", + fileobj: IO[bytes] | None = None, preset: int | None = None, + *, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., dereference: bool | None = ..., @@ -919,9 +840,9 @@ class TarFile: @classmethod def xzopen( cls, - *, fileobj: IO[bytes], - name: StrOrBytesPath | None = None, + *, + name: StrOrBytesPath | None, mode: Literal["r", "w", "x"] = "r", preset: int | None = None, format: int | None = ..., @@ -938,6 +859,8 @@ class TarFile: def getnames(self) -> _list[str]: ... def list(self, verbose: bool = True, *, members: _list[TarInfo] | None = None) -> None: ... def next(self) -> TarInfo | None: ... + # Calling this method without `filter` is deprecated, but it may be set either on the class or in an + # individual call, so we can't mark it as @deprecated here. def extractall( self, path: StrOrBytesPath = ".", @@ -946,6 +869,7 @@ class TarFile: numeric_owner: bool = False, filter: _TarfileFilter | None = ..., ) -> None: ... + # Same situation as for `extractall`. def extract( self, member: str | TarInfo, @@ -955,7 +879,9 @@ class TarFile: numeric_owner: bool = False, filter: _TarfileFilter | None = ..., ) -> None: ... - def _extract_member(self, tarinfo: TarInfo, targetpath: str, set_attrs: bool = True, numeric_owner: bool = False) -> None: ... + def _extract_member( + self, tarinfo: TarInfo, targetpath: str, set_attrs: bool = True, numeric_owner: bool = False + ) -> None: ... # undocumented def extractfile(self, member: str | TarInfo) -> IO[bytes] | None: ... def makedir(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented def makefile(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented @@ -963,9 +889,6 @@ class TarFile: def makefifo(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented def makedev(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented def makelink(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented - def makelink_with_filter( - self, tarinfo: TarInfo, targetpath: StrOrBytesPath, filter_function: _FilterFunction, extraction_root: str - ) -> None: ... # undocumented def chown(self, tarinfo: TarInfo, targetpath: StrOrBytesPath, numeric_owner: bool) -> None: ... # undocumented def chmod(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented def utime(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented @@ -995,6 +918,8 @@ class ExtractError(TarError): ... class HeaderError(TarError): ... class FilterError(TarError): + # This attribute is only set directly on the subclasses, but the documentation guarantees + # that it is always present on FilterError. tarinfo: TarInfo class AbsolutePathError(FilterError): @@ -1012,9 +937,6 @@ class AbsoluteLinkError(FilterError): class LinkOutsideDestinationError(FilterError): def __init__(self, tarinfo: TarInfo, path: str) -> None: ... -class LinkFallbackError(FilterError): - def __init__(self, tarinfo: TarInfo, path: str) -> None: ... - def fully_trusted_filter(member: TarInfo, dest_path: str) -> TarInfo: ... def tar_filter(member: TarInfo, dest_path: str) -> TarInfo: ... def data_filter(member: TarInfo, dest_path: str) -> TarInfo: ... From 785d98e62ab3fa068e89cd2f7f1264cfbcbbcab4 Mon Sep 17 00:00:00 2001 From: Alexeev Bronislav Date: Sat, 5 Jul 2025 02:56:54 +0700 Subject: [PATCH 24/36] revert change --- stdlib/tarfile.pyi | 286 +++++++++++++++++++++++++++++---------------- 1 file changed, 188 insertions(+), 98 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index ab4e6d34a328..fa44e721ce3f 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -2,7 +2,7 @@ import bz2 import io 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 builtins import list as _list from collections.abc import Callable, Iterable, Iterator, Mapping from gzip import _ReadableFileobj as _GzipReadableFileobj, _WritableFileobj as _GzipWritableFileobj from types import TracebackType @@ -38,6 +38,8 @@ if sys.version_info >= (3, 12): "AbsolutePathError", "LinkOutsideDestinationError", ] +if sys.version_info >= (3, 13): + __all__ += ["LinkFallbackError"] _FilterFunction: TypeAlias = Callable[[TarInfo, str], TarInfo | None] _TarfileFilter: TypeAlias = Literal["fully_trusted", "tar", "data"] | _FilterFunction @@ -48,9 +50,6 @@ class _Fileobj(Protocol): def tell(self) -> int: ... def seek(self, pos: int, /) -> object: ... def close(self) -> object: ... - # Optional fields: - # name: str | bytes - # mode: Literal["rb", "r+b", "wb", "xb"] class _Bz2ReadableFileobj(bz2._ReadableFileobj): def close(self) -> object: ... @@ -58,7 +57,6 @@ class _Bz2ReadableFileobj(bz2._ReadableFileobj): class _Bz2WritableFileobj(bz2._WritableFileobj): def close(self) -> object: ... -# tar constants NUL: bytes BLOCKSIZE: int RECORDSIZE: int @@ -92,8 +90,6 @@ GNU_FORMAT: int PAX_FORMAT: int DEFAULT_FORMAT: int -# tarfile constants - SUPPORTED_TYPES: tuple[bytes, ...] REGULAR_TYPES: tuple[bytes, ...] GNU_TYPES: tuple[bytes, ...] @@ -121,8 +117,9 @@ class TarFile: pax_headers: Mapping[str, str] | None debug: int | None errorlevel: int | None - offset: int # undocumented + offset: int extraction_filter: _FilterFunction | None + if sys.version_info >= (3, 13): stream: bool @overload @@ -144,24 +141,6 @@ class TarFile: stream: bool = False, ) -> None: ... @overload - def __init__( - self, - name: StrOrBytesPath | None = None, - mode: Literal["r", "a", "w", "x"] = "r", - fileobj: _Fileobj | None = None, - format: int | None = None, - tarinfo: type[TarInfo] | None = None, - dereference: bool | None = None, - ignore_zeros: bool | None = None, - encoding: str | None = None, - errors: str = "surrogateescape", - pax_headers: Mapping[str, str] | None = None, - debug: int | None = None, - errorlevel: int | None = None, - copybufsize: int | None = None, - stream: bool = False, - ) -> None: ... - @overload def __init__( self, fileobj: _Fileobj, @@ -199,23 +178,6 @@ class TarFile: copybufsize: int | None = None, ) -> None: ... @overload - def __init__( - self, - name: StrOrBytesPath | None = None, - mode: Literal["r", "a", "w", "x"] = "r", - fileobj: _Fileobj | None = None, - format: int | None = None, - tarinfo: type[TarInfo] | None = None, - dereference: bool | None = None, - ignore_zeros: bool | None = None, - encoding: str | None = None, - errors: str = "surrogateescape", - pax_headers: Mapping[str, str] | None = None, - debug: int | None = None, - errorlevel: int | None = None, - copybufsize: int | None = None, - ) -> None: ... - @overload def __init__( self, fileobj: _Fileobj, @@ -239,6 +201,7 @@ class TarFile: self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> None: ... def __iter__(self) -> Iterator[TarInfo]: ... + @overload @classmethod def open( @@ -262,11 +225,11 @@ class TarFile: @classmethod def open( cls, + fileobj: _Fileobj, + *, name: StrOrBytesPath | None = None, mode: Literal["r", "r:*", "r:", "r:gz", "r:bz2", "r:xz"] = "r", - fileobj: _Fileobj | None = None, bufsize: int = 10240, - *, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., dereference: bool | None = ..., @@ -281,8 +244,8 @@ class TarFile: @classmethod def open( cls, - fileobj: _Fileobj, *, + fileobj: _Fileobj, name: StrOrBytesPath | None = None, mode: Literal["r", "r:*", "r:", "r:gz", "r:bz2", "r:xz"] = "r", bufsize: int = 10240, @@ -296,11 +259,12 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload @classmethod def open( cls, - name: StrOrBytesPath | None, + name: StrOrBytesPath, mode: Literal["x", "x:", "a", "a:", "w", "w:", "w:tar"], fileobj: _Fileobj | None = None, bufsize: int = 10240, @@ -319,10 +283,29 @@ class TarFile: @classmethod def open( cls, + fileobj: _Fileobj, + *, name: StrOrBytesPath | None = None, + mode: Literal["x", "x:", "a", "a:", "w", "w:", "w:tar"], + 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 = ..., + ) -> Self: ... + @overload + @classmethod + def open( + cls, *, + fileobj: _Fileobj, + name: StrOrBytesPath | None = None, mode: Literal["x", "x:", "a", "a:", "w", "w:", "w:tar"], - fileobj: _Fileobj | None = None, bufsize: int = 10240, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., @@ -334,11 +317,12 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload @classmethod def open( cls, - name: StrOrBytesPath | None, + name: StrOrBytesPath, mode: Literal["x:gz", "x:bz2", "w:gz", "w:bz2"], fileobj: _Fileobj | None = None, bufsize: int = 10240, @@ -358,10 +342,30 @@ class TarFile: @classmethod def open( cls, + fileobj: _Fileobj, + *, name: StrOrBytesPath | None = None, + mode: Literal["x:gz", "x:bz2", "w:gz", "w:bz2"], + 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 = ..., + compresslevel: int = 9, + ) -> Self: ... + @overload + @classmethod + def open( + cls, *, + fileobj: _Fileobj, + name: StrOrBytesPath | None = None, mode: Literal["x:gz", "x:bz2", "w:gz", "w:bz2"], - fileobj: _Fileobj | None = None, bufsize: int = 10240, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., @@ -374,11 +378,12 @@ class TarFile: errorlevel: int | None = ..., compresslevel: int = 9, ) -> Self: ... + @overload @classmethod def open( cls, - name: StrOrBytesPath | None, + name: StrOrBytesPath, mode: Literal["x:xz", "w:xz"], fileobj: _Fileobj | None = None, bufsize: int = 10240, @@ -398,10 +403,30 @@ class TarFile: @classmethod def open( cls, + fileobj: _Fileobj, + *, name: StrOrBytesPath | None = None, + mode: Literal["x:xz", "w:xz"], + 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 = ..., + preset: Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | None = ..., + ) -> Self: ... + @overload + @classmethod + def open( + cls, *, + fileobj: _Fileobj, + name: StrOrBytesPath | None = None, mode: Literal["x:xz", "w:xz"], - fileobj: _Fileobj | None = None, bufsize: int = 10240, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., @@ -414,11 +439,12 @@ class TarFile: errorlevel: int | None = ..., preset: Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | None = ..., ) -> Self: ... + @overload @classmethod def open( cls, - name: StrOrBytesPath | ReadableBuffer | None, + name: StrOrBytesPath | ReadableBuffer, mode: Literal["r|*", "r|", "r|gz", "r|bz2", "r|xz"], fileobj: _Fileobj | None = None, bufsize: int = 10240, @@ -437,10 +463,29 @@ class TarFile: @classmethod def open( cls, + fileobj: _Fileobj, + *, name: StrOrBytesPath | ReadableBuffer | None = None, + mode: Literal["r|*", "r|", "r|gz", "r|bz2", "r|xz"], + 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 = ..., + ) -> Self: ... + @overload + @classmethod + def open( + cls, *, + fileobj: _Fileobj, + name: StrOrBytesPath | ReadableBuffer | None = None, mode: Literal["r|*", "r|", "r|gz", "r|bz2", "r|xz"], - fileobj: _Fileobj | None = None, bufsize: int = 10240, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., @@ -452,11 +497,12 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload @classmethod def open( cls, - name: StrOrBytesPath | WriteableBuffer | None, + name: StrOrBytesPath | WriteableBuffer, mode: Literal["w|", "w|xz"], fileobj: _Fileobj | None = None, bufsize: int = 10240, @@ -475,10 +521,29 @@ class TarFile: @classmethod def open( cls, + fileobj: _Fileobj, + *, name: StrOrBytesPath | WriteableBuffer | None = None, + mode: Literal["w|", "w|xz"], + 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 = ..., + ) -> Self: ... + @overload + @classmethod + def open( + cls, *, + fileobj: _Fileobj, + name: StrOrBytesPath | WriteableBuffer | None = None, mode: Literal["w|", "w|xz"], - fileobj: _Fileobj | None = None, bufsize: int = 10240, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., @@ -490,11 +555,12 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload @classmethod def open( cls, - name: StrOrBytesPath | WriteableBuffer | None, + name: StrOrBytesPath | WriteableBuffer, mode: Literal["w|gz", "w|bz2"], fileobj: _Fileobj | None = None, bufsize: int = 10240, @@ -514,10 +580,30 @@ class TarFile: @classmethod def open( cls, + fileobj: _Fileobj, + *, name: StrOrBytesPath | WriteableBuffer | None = None, + mode: Literal["w|gz", "w|bz2"], + 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 = ..., + compresslevel: int = 9, + ) -> Self: ... + @overload + @classmethod + def open( + cls, *, + fileobj: _Fileobj, + name: StrOrBytesPath | WriteableBuffer | None = None, mode: Literal["w|gz", "w|bz2"], - fileobj: _Fileobj | None = None, bufsize: int = 10240, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., @@ -530,6 +616,7 @@ class TarFile: errorlevel: int | None = ..., compresslevel: int = 9, ) -> Self: ... + @overload @classmethod def taropen( @@ -552,10 +639,10 @@ class TarFile: @classmethod def taropen( cls, - name: StrOrBytesPath | None, - mode: Literal["r", "a", "w", "x"] = "r", - fileobj: _Fileobj | None = None, + fileobj: _Fileobj, *, + name: StrOrBytesPath | None = None, + mode: Literal["r", "a", "w", "x"] = "r", compresslevel: int = ..., format: int | None = ..., tarinfo: type[TarInfo] | None = ..., @@ -570,9 +657,9 @@ class TarFile: @classmethod def taropen( cls, - fileobj: _Fileobj, *, - name: StrOrBytesPath | None, + fileobj: _Fileobj, + name: StrOrBytesPath | None = None, mode: Literal["r", "a", "w", "x"] = "r", compresslevel: int = ..., format: int | None = ..., @@ -584,6 +671,7 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload @classmethod def gzopen( @@ -624,11 +712,11 @@ class TarFile: @classmethod def gzopen( cls, - name: StrOrBytesPath | None, + fileobj: _GzipReadableFileobj, + *, + name: StrOrBytesPath | None = None, mode: Literal["r"] = "r", - fileobj: _GzipReadableFileobj | None = None, compresslevel: int = 9, - *, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., dereference: bool | None = ..., @@ -642,11 +730,11 @@ class TarFile: @classmethod def gzopen( cls, - name: StrOrBytesPath | None, + fileobj: _GzipWritableFileobj, + *, + name: StrOrBytesPath | None = None, mode: Literal["w", "x"], - fileobj: _GzipWritableFileobj | None = None, compresslevel: int = 9, - *, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., dereference: bool | None = ..., @@ -660,9 +748,9 @@ class TarFile: @classmethod def gzopen( cls, - fileobj: _GzipReadableFileobj, *, - name: StrOrBytesPath | None, + fileobj: _GzipReadableFileobj, + name: StrOrBytesPath | None = None, mode: Literal["r"] = "r", compresslevel: int = 9, format: int | None = ..., @@ -678,9 +766,9 @@ class TarFile: @classmethod def gzopen( cls, - fileobj: _GzipWritableFileobj, *, - name: StrOrBytesPath | None, + fileobj: _GzipWritableFileobj, + name: StrOrBytesPath | None = None, mode: Literal["w", "x"], compresslevel: int = 9, format: int | None = ..., @@ -692,6 +780,7 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload @classmethod def bz2open( @@ -732,11 +821,11 @@ class TarFile: @classmethod def bz2open( cls, - name: StrOrBytesPath | None, - mode: Literal["w", "x"], - fileobj: _Bz2WritableFileobj | None = None, - compresslevel: int = 9, + fileobj: _Bz2ReadableFileobj, *, + name: StrOrBytesPath | None = None, + mode: Literal["r"] = "r", + compresslevel: int = 9, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., dereference: bool | None = ..., @@ -750,11 +839,11 @@ class TarFile: @classmethod def bz2open( cls, - name: StrOrBytesPath | None, - mode: Literal["r"] = "r", - fileobj: _Bz2ReadableFileobj | None = None, - compresslevel: int = 9, + fileobj: _Bz2WritableFileobj, *, + name: StrOrBytesPath | None = None, + mode: Literal["w", "x"], + compresslevel: int = 9, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., dereference: bool | None = ..., @@ -768,9 +857,9 @@ class TarFile: @classmethod def bz2open( cls, - fileobj: _Bz2ReadableFileobj, *, - name: StrOrBytesPath | None, + fileobj: _Bz2ReadableFileobj, + name: StrOrBytesPath | None = None, mode: Literal["r"] = "r", compresslevel: int = 9, format: int | None = ..., @@ -786,9 +875,9 @@ class TarFile: @classmethod def bz2open( cls, - fileobj: _Bz2WritableFileobj, *, - name: StrOrBytesPath | None, + fileobj: _Bz2WritableFileobj, + name: StrOrBytesPath | None = None, mode: Literal["w", "x"], compresslevel: int = 9, format: int | None = ..., @@ -800,6 +889,7 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload @classmethod def xzopen( @@ -822,11 +912,11 @@ class TarFile: @classmethod def xzopen( cls, - name: StrOrBytesPath | None, + fileobj: IO[bytes], + *, + name: StrOrBytesPath | None = None, mode: Literal["r", "w", "x"] = "r", - fileobj: IO[bytes] | None = None, preset: int | None = None, - *, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., dereference: bool | None = ..., @@ -840,9 +930,9 @@ class TarFile: @classmethod def xzopen( cls, - fileobj: IO[bytes], *, - name: StrOrBytesPath | None, + fileobj: IO[bytes], + name: StrOrBytesPath | None = None, mode: Literal["r", "w", "x"] = "r", preset: int | None = None, format: int | None = ..., @@ -854,13 +944,12 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + def getmember(self, name: str) -> TarInfo: ... def getmembers(self) -> _list[TarInfo]: ... def getnames(self) -> _list[str]: ... def list(self, verbose: bool = True, *, members: _list[TarInfo] | None = None) -> None: ... def next(self) -> TarInfo | None: ... - # Calling this method without `filter` is deprecated, but it may be set either on the class or in an - # individual call, so we can't mark it as @deprecated here. def extractall( self, path: StrOrBytesPath = ".", @@ -869,7 +958,6 @@ class TarFile: numeric_owner: bool = False, filter: _TarfileFilter | None = ..., ) -> None: ... - # Same situation as for `extractall`. def extract( self, member: str | TarInfo, @@ -879,9 +967,7 @@ class TarFile: numeric_owner: bool = False, filter: _TarfileFilter | None = ..., ) -> None: ... - def _extract_member( - self, tarinfo: TarInfo, targetpath: str, set_attrs: bool = True, numeric_owner: bool = False - ) -> None: ... # undocumented + def _extract_member(self, tarinfo: TarInfo, targetpath: str, set_attrs: bool = True, numeric_owner: bool = False) -> None: ... def extractfile(self, member: str | TarInfo) -> IO[bytes] | None: ... def makedir(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented def makefile(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented @@ -889,6 +975,9 @@ class TarFile: def makefifo(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented def makedev(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented def makelink(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented + def makelink_with_filter( + self, tarinfo: TarInfo, targetpath: StrOrBytesPath, filter_function: _FilterFunction, extraction_root: str + ) -> None: ... # undocumented def chown(self, tarinfo: TarInfo, targetpath: StrOrBytesPath, numeric_owner: bool) -> None: ... # undocumented def chmod(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented def utime(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented @@ -918,8 +1007,6 @@ class ExtractError(TarError): ... class HeaderError(TarError): ... class FilterError(TarError): - # This attribute is only set directly on the subclasses, but the documentation guarantees - # that it is always present on FilterError. tarinfo: TarInfo class AbsolutePathError(FilterError): @@ -937,6 +1024,9 @@ class AbsoluteLinkError(FilterError): class LinkOutsideDestinationError(FilterError): def __init__(self, tarinfo: TarInfo, path: str) -> None: ... +class LinkFallbackError(FilterError): + def __init__(self, tarinfo: TarInfo, path: str) -> None: ... + def fully_trusted_filter(member: TarInfo, dest_path: str) -> TarInfo: ... def tar_filter(member: TarInfo, dest_path: str) -> TarInfo: ... def data_filter(member: TarInfo, dest_path: str) -> TarInfo: ... From 39b75daccb9efb8327910d86a0bd9047dfaf9082 Mon Sep 17 00:00:00 2001 From: Alexeev Bronislav Date: Sat, 5 Jul 2025 02:59:33 +0700 Subject: [PATCH 25/36] fix override for xzopen --- stdlib/tarfile.pyi | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index fa44e721ce3f..683a52c7ac67 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -890,6 +890,24 @@ class TarFile: errorlevel: int | None = ..., ) -> Self: ... + @overload + @classmethod + def xzopen( + cls, + name: StrOrBytesPath | None = None, + mode: Literal["r", "w", "x"] = "r", + fileobj: IO[bytes] | None = None, + preset: int | 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 xzopen( From 84696311ae96215a4386824ebe018acf3d0efe3b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 4 Jul 2025 19:59:39 +0000 Subject: [PATCH 26/36] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/tarfile.pyi | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 683a52c7ac67..56a59c3b5dab 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -201,7 +201,6 @@ class TarFile: self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> None: ... def __iter__(self) -> Iterator[TarInfo]: ... - @overload @classmethod def open( @@ -259,7 +258,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - @overload @classmethod def open( @@ -317,7 +315,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - @overload @classmethod def open( @@ -378,7 +375,6 @@ class TarFile: errorlevel: int | None = ..., compresslevel: int = 9, ) -> Self: ... - @overload @classmethod def open( @@ -439,7 +435,6 @@ class TarFile: errorlevel: int | None = ..., preset: Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | None = ..., ) -> Self: ... - @overload @classmethod def open( @@ -497,7 +492,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - @overload @classmethod def open( @@ -555,7 +549,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - @overload @classmethod def open( @@ -616,7 +609,6 @@ class TarFile: errorlevel: int | None = ..., compresslevel: int = 9, ) -> Self: ... - @overload @classmethod def taropen( @@ -671,7 +663,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - @overload @classmethod def gzopen( @@ -780,7 +771,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - @overload @classmethod def bz2open( @@ -889,7 +879,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - @overload @classmethod def xzopen( @@ -962,7 +951,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - def getmember(self, name: str) -> TarInfo: ... def getmembers(self) -> _list[TarInfo]: ... def getnames(self) -> _list[str]: ... From 9962f172600a0919bfd60280fa768c3391ead459 Mon Sep 17 00:00:00 2001 From: Alexeev Bronislav Date: Sat, 5 Jul 2025 03:03:17 +0700 Subject: [PATCH 27/36] fix override for xzopen --- stdlib/tarfile.pyi | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 56a59c3b5dab..4a6b00889e16 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -899,24 +899,6 @@ class TarFile: ) -> Self: ... @overload @classmethod - def xzopen( - cls, - name: StrOrBytesPath, - mode: Literal["r", "w", "x"] = "r", - fileobj: IO[bytes] | None = None, - preset: int | 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 xzopen( cls, fileobj: IO[bytes], @@ -933,24 +915,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - @overload - @classmethod - def xzopen( - cls, - *, - fileobj: IO[bytes], - name: StrOrBytesPath | None = None, - mode: Literal["r", "w", "x"] = "r", - preset: int | 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 b1856590bcd46d21d421d6684d21c351dac0157d Mon Sep 17 00:00:00 2001 From: Alexeev Bronislav Date: Sat, 5 Jul 2025 03:06:01 +0700 Subject: [PATCH 28/36] fix override for xzopen --- stdlib/tarfile.pyi | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 4a6b00889e16..d9f41ce4ea98 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -201,6 +201,7 @@ class TarFile: self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> None: ... def __iter__(self) -> Iterator[TarInfo]: ... + @overload @classmethod def open( @@ -258,6 +259,7 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload @classmethod def open( @@ -315,6 +317,7 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload @classmethod def open( @@ -375,6 +378,7 @@ class TarFile: errorlevel: int | None = ..., compresslevel: int = 9, ) -> Self: ... + @overload @classmethod def open( @@ -435,6 +439,7 @@ class TarFile: errorlevel: int | None = ..., preset: Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | None = ..., ) -> Self: ... + @overload @classmethod def open( @@ -492,6 +497,7 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload @classmethod def open( @@ -549,6 +555,7 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload @classmethod def open( @@ -609,6 +616,7 @@ class TarFile: errorlevel: int | None = ..., compresslevel: int = 9, ) -> Self: ... + @overload @classmethod def taropen( @@ -663,6 +671,7 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload @classmethod def gzopen( @@ -771,6 +780,7 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload @classmethod def bz2open( @@ -879,13 +889,14 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload @classmethod def xzopen( cls, - name: StrOrBytesPath | None = None, + name: StrOrBytesPath, + fileobj: IO[bytes], mode: Literal["r", "w", "x"] = "r", - fileobj: IO[bytes] | None = None, preset: int | None = None, *, format: int | None = ..., @@ -915,6 +926,25 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload + @classmethod + def xzopen( + cls, + *, + fileobj: IO[bytes], + name: StrOrBytesPath | None = None, + mode: Literal["r", "w", "x"] = "r", + preset: int | 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 6986131e73fe1245e5a52a0939dd3051684291f4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 4 Jul 2025 20:07:53 +0000 Subject: [PATCH 29/36] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/tarfile.pyi | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index d9f41ce4ea98..2ecbd7dee1c9 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -201,7 +201,6 @@ class TarFile: self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> None: ... def __iter__(self) -> Iterator[TarInfo]: ... - @overload @classmethod def open( @@ -259,7 +258,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - @overload @classmethod def open( @@ -317,7 +315,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - @overload @classmethod def open( @@ -378,7 +375,6 @@ class TarFile: errorlevel: int | None = ..., compresslevel: int = 9, ) -> Self: ... - @overload @classmethod def open( @@ -439,7 +435,6 @@ class TarFile: errorlevel: int | None = ..., preset: Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | None = ..., ) -> Self: ... - @overload @classmethod def open( @@ -497,7 +492,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - @overload @classmethod def open( @@ -555,7 +549,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - @overload @classmethod def open( @@ -616,7 +609,6 @@ class TarFile: errorlevel: int | None = ..., compresslevel: int = 9, ) -> Self: ... - @overload @classmethod def taropen( @@ -671,7 +663,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - @overload @classmethod def gzopen( @@ -780,7 +771,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - @overload @classmethod def bz2open( @@ -889,7 +879,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - @overload @classmethod def xzopen( @@ -944,7 +933,6 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... - def getmember(self, name: str) -> TarInfo: ... def getmembers(self) -> _list[TarInfo]: ... def getnames(self) -> _list[str]: ... From 514cc8ded2eb1aca438d93fdbfebfdd924d8c841 Mon Sep 17 00:00:00 2001 From: Alexeev Bronislav Date: Sat, 5 Jul 2025 03:08:11 +0700 Subject: [PATCH 30/36] fix override for xzopen --- stdlib/tarfile.pyi | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index d9f41ce4ea98..a652a30d4a07 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -895,8 +895,8 @@ class TarFile: def xzopen( cls, name: StrOrBytesPath, - fileobj: IO[bytes], mode: Literal["r", "w", "x"] = "r", + fileobj: IO[bytes] | None = None, preset: int | None = None, *, format: int | None = ..., @@ -944,6 +944,24 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload + @classmethod + def xzopen( + cls, + *, + fileobj: IO[bytes] | None = None, + name: StrOrBytesPath | None = None, + mode: Literal["r", "w", "x"] = "r", + preset: int | 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]: ... From ec43fbe7837e4bd76b851ab0a67da56b60e8abc2 Mon Sep 17 00:00:00 2001 From: Alexeev Bronislav Date: Sat, 5 Jul 2025 03:09:00 +0700 Subject: [PATCH 31/36] fix override for xzopen --- stdlib/tarfile.pyi | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 51a9bcd731a2..5e23f2cdc607 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -933,6 +933,24 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload + @classmethod + def xzopen( + cls, + *, + fileobj: IO[bytes] = None, + name: StrOrBytesPath | None = None, + mode: Literal["r", "w", "x"] = "r", + preset: int | 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 11e9ef3304278a0a917c259e773bb3310daf4269 Mon Sep 17 00:00:00 2001 From: Alexeev Bronislav Date: Sat, 5 Jul 2025 03:42:35 +0700 Subject: [PATCH 32/36] fix stubtest erros --- stdlib/tarfile.pyi | 42 ++++++++++++------------------------------ 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 5e23f2cdc607..c40389752ad0 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -633,7 +633,7 @@ class TarFile: cls, fileobj: _Fileobj, *, - name: StrOrBytesPath | None = None, + name: StrOrBytesPath, mode: Literal["r", "a", "w", "x"] = "r", compresslevel: int = ..., format: int | None = ..., @@ -651,7 +651,7 @@ class TarFile: cls, *, fileobj: _Fileobj, - name: StrOrBytesPath | None = None, + name: StrOrBytesPath, mode: Literal["r", "a", "w", "x"] = "r", compresslevel: int = ..., format: int | None = ..., @@ -705,7 +705,7 @@ class TarFile: cls, fileobj: _GzipReadableFileobj, *, - name: StrOrBytesPath | None = None, + name: StrOrBytesPath, mode: Literal["r"] = "r", compresslevel: int = 9, format: int | None = ..., @@ -723,7 +723,7 @@ class TarFile: cls, fileobj: _GzipWritableFileobj, *, - name: StrOrBytesPath | None = None, + name: StrOrBytesPath, mode: Literal["w", "x"], compresslevel: int = 9, format: int | None = ..., @@ -741,7 +741,7 @@ class TarFile: cls, *, fileobj: _GzipReadableFileobj, - name: StrOrBytesPath | None = None, + name: StrOrBytesPath, mode: Literal["r"] = "r", compresslevel: int = 9, format: int | None = ..., @@ -759,7 +759,7 @@ class TarFile: cls, *, fileobj: _GzipWritableFileobj, - name: StrOrBytesPath | None = None, + name: StrOrBytesPath, mode: Literal["w", "x"], compresslevel: int = 9, format: int | None = ..., @@ -813,7 +813,7 @@ class TarFile: cls, fileobj: _Bz2ReadableFileobj, *, - name: StrOrBytesPath | None = None, + name: StrOrBytesPath, mode: Literal["r"] = "r", compresslevel: int = 9, format: int | None = ..., @@ -831,7 +831,7 @@ class TarFile: cls, fileobj: _Bz2WritableFileobj, *, - name: StrOrBytesPath | None = None, + name: StrOrBytesPath, mode: Literal["w", "x"], compresslevel: int = 9, format: int | None = ..., @@ -849,7 +849,7 @@ class TarFile: cls, *, fileobj: _Bz2ReadableFileobj, - name: StrOrBytesPath | None = None, + name: StrOrBytesPath, mode: Literal["r"] = "r", compresslevel: int = 9, format: int | None = ..., @@ -867,7 +867,7 @@ class TarFile: cls, *, fileobj: _Bz2WritableFileobj, - name: StrOrBytesPath | None = None, + name: StrOrBytesPath, mode: Literal["w", "x"], compresslevel: int = 9, format: int | None = ..., @@ -903,7 +903,7 @@ class TarFile: cls, fileobj: IO[bytes], *, - name: StrOrBytesPath | None = None, + name: StrOrBytesPath, mode: Literal["r", "w", "x"] = "r", preset: int | None = None, format: int | None = ..., @@ -921,25 +921,7 @@ class TarFile: cls, *, fileobj: IO[bytes], - name: StrOrBytesPath | None = None, - mode: Literal["r", "w", "x"] = "r", - preset: int | 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 xzopen( - cls, - *, - fileobj: IO[bytes] = None, - name: StrOrBytesPath | None = None, + name: StrOrBytesPath, mode: Literal["r", "w", "x"] = "r", preset: int | None = None, format: int | None = ..., From 2f4f03b2b4430a584882e09a95ea62842ee8d660 Mon Sep 17 00:00:00 2001 From: Alexeev Bronislav Date: Sat, 5 Jul 2025 04:04:51 +0700 Subject: [PATCH 33/36] fix _extract_member stubtest error for 3.13 --- stdlib/tarfile.pyi | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index c40389752ad0..74cd93b1bda3 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -955,7 +955,25 @@ class TarFile: numeric_owner: bool = False, filter: _TarfileFilter | None = ..., ) -> None: ... - def _extract_member(self, tarinfo: TarInfo, targetpath: str, set_attrs: bool = True, numeric_owner: bool = False) -> None: ... + if sys.version_info >= (3, 13): + def _extract_member( + self, + tarinfo: TarInfo, + targetpath: str, + set_attrs: bool = True, + numeric_owner: bool = False, + *, + filter_function: _FilterFunction | None = ..., + extraction_root: str | None = ..., + ) -> None: ... + else: + def _extract_member( + self, + tarinfo: TarInfo, + targetpath: str, + set_attrs: bool = True, + numeric_owner: bool = False, + ) -> None: ... def extractfile(self, member: str | TarInfo) -> IO[bytes] | None: ... def makedir(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented def makefile(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented From d3f531264f2a53fc0c68dc2e68319626091bef07 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 4 Jul 2025 21:08:35 +0000 Subject: [PATCH 34/36] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/tarfile.pyi | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 74cd93b1bda3..895ddf57af40 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -968,12 +968,9 @@ class TarFile: ) -> None: ... else: def _extract_member( - self, - tarinfo: TarInfo, - targetpath: str, - set_attrs: bool = True, - numeric_owner: bool = False, + self, tarinfo: TarInfo, targetpath: str, set_attrs: bool = True, numeric_owner: bool = False ) -> None: ... + def extractfile(self, member: str | TarInfo) -> IO[bytes] | None: ... def makedir(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented def makefile(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented From 4ebcaa7d337a7cc913b608d903b0115df8267f07 Mon Sep 17 00:00:00 2001 From: Alexeev Bronislav Date: Wed, 16 Jul 2025 23:39:10 +0700 Subject: [PATCH 35/36] try fix overloads for open --- stdlib/@tests/stubtest_allowlists/common.txt | 2 -- stdlib/tarfile.pyi | 21 +------------------- 2 files changed, 1 insertion(+), 22 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/common.txt b/stdlib/@tests/stubtest_allowlists/common.txt index a84947e7eafc..130c6d2b8285 100644 --- a/stdlib/@tests/stubtest_allowlists/common.txt +++ b/stdlib/@tests/stubtest_allowlists/common.txt @@ -556,5 +556,3 @@ xml.etree.cElementTree.XMLParser.__init__ # Defined in C so has general signatu # These would ideally be special-cased by type checkers; see https://github.com/python/mypy/issues/2220 xml.etree.ElementTree.Element.__iter__ xml.etree.cElementTree.Element.__iter__ - -tarfile.open # Overridden by TarFile.open diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 74cd93b1bda3..c3e99f70a289 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -2,7 +2,7 @@ import bz2 import io import sys from _typeshed import ReadableBuffer, StrOrBytesPath, StrPath, SupportsRead, WriteableBuffer -from builtins import list as _list +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 gzip import _ReadableFileobj as _GzipReadableFileobj, _WritableFileobj as _GzipWritableFileobj from types import TracebackType @@ -279,25 +279,6 @@ class TarFile: ) -> Self: ... @overload @classmethod - def open( - cls, - fileobj: _Fileobj, - *, - name: StrOrBytesPath | None = None, - mode: Literal["x", "x:", "a", "a:", "w", "w:", "w:tar"], - 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 = ..., - ) -> Self: ... - @overload - @classmethod def open( cls, *, From f41e41bc37e36f73f12b625a4e36ec840c22dd1c Mon Sep 17 00:00:00 2001 From: Alexeev Bronislav Date: Fri, 18 Jul 2025 19:33:59 +0700 Subject: [PATCH 36/36] try fix it... --- stdlib/tarfile.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 61140124830c..65db95cd55f0 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -224,8 +224,8 @@ class TarFile: @classmethod def open( cls, - fileobj: _Fileobj, *, + fileobj: _Fileobj, name: StrOrBytesPath | None = None, mode: Literal["r", "r:*", "r:", "r:gz", "r:bz2", "r:xz"] = "r", bufsize: int = 10240, @@ -244,7 +244,7 @@ class TarFile: def open( cls, *, - fileobj: _Fileobj, + fileobj: _Fileobj | None = None, name: StrOrBytesPath | None = None, mode: Literal["r", "r:*", "r:", "r:gz", "r:bz2", "r:xz"] = "r", bufsize: int = 10240,