Skip to content

Commit

Permalink
Fix tarfile.open overloads
Browse files Browse the repository at this point in the history
* Allow `compresslevel` argument for modes `w|gz` and `w|bz2`.
* Remove `preset` argument from modes where it's not allowed.

Closes: python#13440
  • Loading branch information
srittau committed Jan 27, 2025
1 parent 89b49d2 commit 5486c4a
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions stdlib/tarfile.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ...,
Expand All @@ -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):
Expand Down

0 comments on commit 5486c4a

Please sign in to comment.