From 4bd33410a96cf2b61a0443fceecefd43ac1105a4 Mon Sep 17 00:00:00 2001 From: Edward Peek Date: Fri, 11 Apr 2025 18:05:51 +1200 Subject: [PATCH 1/2] Add test case for `tarfile.open` pipe modes --- stdlib/@tests/test_cases/check_tarfile.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stdlib/@tests/test_cases/check_tarfile.py b/stdlib/@tests/test_cases/check_tarfile.py index 54510a3d7626..815a6350c837 100644 --- a/stdlib/@tests/test_cases/check_tarfile.py +++ b/stdlib/@tests/test_cases/check_tarfile.py @@ -11,3 +11,7 @@ # Test with invalid preset values tarfile.open("test.tar.xz", "w:xz", preset=-1) # type: ignore tarfile.open("test.tar.xz", "w:xz", preset=10) # type: ignore + +# Test pipe modes +tarfile.open("test.tar.xz", "r|*") +tarfile.open("test.tar.xz", mode="r|*") From 0710b8370bfe3428c9b696dc340067a912cfdbff Mon Sep 17 00:00:00 2001 From: Edward Peek Date: Fri, 11 Apr 2025 16:56:32 +1200 Subject: [PATCH 2/2] Fix incorrectly keyword-only arguments in `tarfile.open` --- stdlib/tarfile.pyi | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 51195eb98fcc..cd31b101c886 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -304,6 +304,25 @@ class TarFile: ) -> Self: ... @overload @classmethod + def open( + cls, + name: StrOrBytesPath | ReadableBuffer | 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 = ..., + 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 | ReadableBuffer | None = None, @@ -323,6 +342,25 @@ class TarFile: ) -> Self: ... @overload @classmethod + def open( + cls, + name: StrOrBytesPath | WriteableBuffer | None, + mode: Literal["w|", "w|xz"], + 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, name: StrOrBytesPath | WriteableBuffer | None = None, @@ -342,6 +380,26 @@ class TarFile: ) -> Self: ... @overload @classmethod + def open( + cls, + name: StrOrBytesPath | WriteableBuffer | None, + mode: Literal["w|gz", "w|bz2"], + 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 = ..., + compresslevel: int = 9, + ) -> Self: ... + @overload + @classmethod def open( cls, name: StrOrBytesPath | WriteableBuffer | None = None,