From e35437133b4ca9c6537f11724f482c8f79a430d2 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Sat, 8 Jun 2024 13:44:08 -0500 Subject: [PATCH 1/2] Update tarfile.pyi with open() function overloads --- stdlib/tarfile.pyi | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index e52099464174..2c30d4be73f2 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -103,10 +103,37 @@ PAX_NAME_FIELDS: set[str] ENCODING: str +_ReadModes: TypeAlias = Literal["r", "r:"] +_CompressionModes: TypeAlias = Literal[ + "r:", "r:gz", "r:bz2", "r:xz", "w:", "w:gz", "w:bz2", "w:xz", "x:", "x:gz", "x:bz2", "x:xz" +] +_StreamModes: TypeAlias = Literal["r|*", "r|", "r|gz", "r|bz2", "r|xz", "w|", "w|gz", "w|bz2", "w|xz"] +_FileCreationModes: TypeAlias = Literal["a", "w", "x"] + +@overload +def open( + name: StrOrBytesPath | None = None, + mode: _ReadModes | _CompressionModes | _StreamModes = "r", + 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 | None = ..., + preset: Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | None = ..., +) -> TarFile: ... +@overload def open( name: StrOrBytesPath | None = None, - mode: str = "r", - fileobj: IO[bytes] | None = None, # depends on mode + mode: _FileCreationModes = ..., + fileobj: _Fileobj | None = None, bufsize: int = 10240, *, format: int | None = ..., From d33165b898fad10ce8216e4a9f4b25840d03bf48 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Sat, 8 Jun 2024 14:00:35 -0500 Subject: [PATCH 2/2] Revert --- stdlib/tarfile.pyi | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 2c30d4be73f2..9a95db9d2c79 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -103,17 +103,12 @@ PAX_NAME_FIELDS: set[str] ENCODING: str -_ReadModes: TypeAlias = Literal["r", "r:"] -_CompressionModes: TypeAlias = Literal[ - "r:", "r:gz", "r:bz2", "r:xz", "w:", "w:gz", "w:bz2", "w:xz", "x:", "x:gz", "x:bz2", "x:xz" -] -_StreamModes: TypeAlias = Literal["r|*", "r|", "r|gz", "r|bz2", "r|xz", "w|", "w|gz", "w|bz2", "w|xz"] _FileCreationModes: TypeAlias = Literal["a", "w", "x"] @overload def open( name: StrOrBytesPath | None = None, - mode: _ReadModes | _CompressionModes | _StreamModes = "r", + mode: str = "r", fileobj: IO[bytes] | None = None, bufsize: int = 10240, *,