Skip to content

stdlib: Fix missing overloads in tarfile.TarFile to prevent None/None case #14170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 155 additions & 7 deletions stdlib/tarfile.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ class TarFile:
extraction_filter: _FilterFunction | None
if sys.version_info >= (3, 13):
stream: bool
@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,
Expand All @@ -142,11 +143,30 @@ class TarFile:
copybufsize: int | None = None, # undocumented
stream: bool = False,
) -> None: ...
else:
@overload
def __init__(
self,
name: StrOrBytesPath | None = None,
mode: Literal["r", "a", "w", "x"] = "r",
fileobj: _Fileobj = ...,
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:
@overload
def __init__(
self,
name: StrOrBytesPath,
mode: Literal["r", "a", "w", "x"] = "r",
fileobj: _Fileobj | None = None,
format: int | None = None,
tarinfo: type[TarInfo] | None = None,
Expand All @@ -159,6 +179,23 @@ class TarFile:
errorlevel: int | None = None,
copybufsize: int | None = None, # undocumented
) -> None: ...
@overload
def __init__(
self,
name: StrOrBytesPath | None = None,
mode: Literal["r", "a", "w", "x"] = "r",
fileobj: _Fileobj = ...,
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__(
Expand All @@ -169,7 +206,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,
Expand All @@ -186,6 +223,25 @@ class TarFile:
) -> Self: ...
@overload
@classmethod
def open(
cls,
name: StrOrBytesPath | None,
mode: Literal["r", "r:*", "r:", "r:gz", "r:bz2", "r:xz"] = "r",
fileobj: _Fileobj = ...,
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,
Expand Down Expand Up @@ -418,10 +474,11 @@ class TarFile:
errorlevel: int | None = ...,
compresslevel: int = 9,
) -> Self: ...
@overload
@classmethod
def taropen(
cls,
name: StrOrBytesPath | None,
name: StrOrBytesPath,
mode: Literal["r", "a", "w", "x"] = "r",
fileobj: _Fileobj | None = None,
*,
Expand All @@ -437,9 +494,27 @@ class TarFile:
) -> Self: ...
@overload
@classmethod
def gzopen(
def taropen(
cls,
name: StrOrBytesPath | None,
mode: Literal["r", "a", "w", "x"] = "r",
fileobj: _Fileobj = ...,
*,
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,
mode: Literal["r"] = "r",
fileobj: _GzipReadableFileobj | None = None,
compresslevel: int = 9,
Expand All @@ -455,6 +530,24 @@ class TarFile:
) -> Self: ...
@overload
@classmethod
def gzopen(
cls,
name: StrOrBytesPath | None,
mode: Literal["r"] = "r",
fileobj: _GzipReadableFileobj = ...,
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 | None,
Expand All @@ -475,7 +568,7 @@ class TarFile:
@classmethod
def bz2open(
cls,
name: StrOrBytesPath | None,
name: StrOrBytesPath,
mode: Literal["w", "x"],
fileobj: _Bz2WritableFileobj | None = None,
compresslevel: int = 9,
Expand All @@ -494,6 +587,24 @@ class TarFile:
def bz2open(
cls,
name: StrOrBytesPath | None,
mode: Literal["w", "x"] = ...,
fileobj: _Bz2WritableFileobj = ...,
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,
Expand All @@ -507,10 +618,29 @@ class TarFile:
debug: int | None = ...,
errorlevel: int | None = ...,
) -> Self: ...
@overload
@classmethod
def bz2open(
cls,
name: StrOrBytesPath | None,
mode: Literal["r"] = "r",
fileobj: _Bz2ReadableFileobj = ...,
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,
name: StrOrBytesPath | None,
name: StrOrBytesPath,
mode: Literal["r", "w", "x"] = "r",
fileobj: IO[bytes] | None = None,
preset: int | None = None,
Expand All @@ -524,6 +654,24 @@ class TarFile:
debug: int | None = ...,
errorlevel: int | None = ...,
) -> Self: ...
@overload
@classmethod
def xzopen(
cls,
name: StrOrBytesPath | None,
mode: Literal["r", "w", "x"] = "r",
fileobj: IO[bytes] = ...,
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]: ...
Expand Down