Fix tarfile.open overloads (#13441)

* Allow `compresslevel` argument for modes `w|gz` and `w|bz2`.
* Remove `preset` argument from modes where it's not allowed.

Closes: #13440
This commit is contained in:
Sebastian Rittau
2025-03-06 10:39:56 +01:00
committed by GitHub
parent 91a90ed1d9
commit ba85e0c282
+19 -3
View File
@@ -242,13 +242,12 @@ def open(
pax_headers: Mapping[str, str] | None = ...,
debug: int | None = ...,
errorlevel: int | None = ...,
preset: int | None = ...,
) -> TarFile: ...
@overload
def open(
name: StrOrBytesPath | WriteableBuffer | None = None,
*,
mode: Literal["w|", "w|gz", "w|bz2", "w|xz"],
mode: Literal["w|", "w|xz"],
fileobj: IO[bytes] | None = None,
bufsize: int = 10240,
format: int | None = ...,
@@ -260,7 +259,24 @@ def open(
pax_headers: Mapping[str, str] | None = ...,
debug: int | None = ...,
errorlevel: int | None = ...,
preset: int | None = ...,
) -> TarFile: ...
@overload
def open(
name: StrOrBytesPath | WriteableBuffer | None = None,
*,
mode: Literal["w|gz", "w|bz2"],
fileobj: IO[bytes] | 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,
) -> TarFile: ...
class ExFileObject(io.BufferedReader):