diff --git a/stdlib/@tests/stubtest_allowlists/common.txt b/stdlib/@tests/stubtest_allowlists/common.txt index 130c6d2b8285..a84947e7eafc 100644 --- a/stdlib/@tests/stubtest_allowlists/common.txt +++ b/stdlib/@tests/stubtest_allowlists/common.txt @@ -556,3 +556,5 @@ xml.etree.cElementTree.XMLParser.__init__ # Defined in C so has general signatu # These would ideally be special-cased by type checkers; see https://github.com/python/mypy/issues/2220 xml.etree.ElementTree.Element.__iter__ xml.etree.cElementTree.Element.__iter__ + +tarfile.open # Overridden by TarFile.open diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index a18ef0b823f9..f7c19d8b0692 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -127,6 +127,25 @@ class TarFile: extraction_filter: _FilterFunction | None if sys.version_info >= (3, 13): stream: bool + @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, + 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, + stream: bool = False, + ) -> None: ... + @overload def __init__( self, name: StrOrBytesPath | None = None, @@ -141,10 +160,47 @@ class TarFile: pax_headers: Mapping[str, str] | None = None, debug: int | None = None, errorlevel: int | None = None, - copybufsize: int | None = None, # undocumented + copybufsize: int | None = None, + stream: bool = False, + ) -> None: ... + @overload + def __init__( + self, + fileobj: _Fileobj, + *, + name: StrOrBytesPath | None = None, + mode: Literal["r", "a", "w", "x"] = "r", + 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, 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, + 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, + ) -> None: ... + @overload def __init__( self, name: StrOrBytesPath | None = None, @@ -159,7 +215,25 @@ class TarFile: pax_headers: Mapping[str, str] | None = None, debug: int | None = None, errorlevel: int | None = None, - copybufsize: int | None = None, # undocumented + copybufsize: int | None = None, + ) -> None: ... + @overload + def __init__( + self, + fileobj: _Fileobj, + *, + name: StrOrBytesPath | None = None, + mode: Literal["r", "a", "w", "x"] = "r", + 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, ) -> None: ... def __enter__(self) -> Self: ... @@ -169,6 +243,25 @@ class TarFile: def __iter__(self) -> Iterator[TarInfo]: ... @overload @classmethod + def open( + cls, + name: StrOrBytesPath, + mode: Literal["r", "r:*", "r:", "r:gz", "r:bz2", "r:xz"] = "r", + 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 | None = None, @@ -188,6 +281,25 @@ class TarFile: ) -> Self: ... @overload @classmethod + def open( + cls, + fileobj: _Fileobj, + *, + name: StrOrBytesPath | None = None, + mode: Literal["r", "r:*", "r:", "r:gz", "r:bz2", "r:xz"] = "r", + 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, @@ -420,6 +532,25 @@ class TarFile: errorlevel: int | None = ..., compresslevel: int = 9, ) -> Self: ... + @overload + @classmethod + def taropen( + cls, + name: StrOrBytesPath, + mode: Literal["r", "a", "w", "x"] = "r", + fileobj: _Fileobj | None = None, + *, + 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 taropen( cls, @@ -439,6 +570,60 @@ class TarFile: ) -> Self: ... @overload @classmethod + def taropen( + cls, + fileobj: _Fileobj, + *, + name: StrOrBytesPath | None, + mode: Literal["r", "a", "w", "x"] = "r", + 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, + *, + 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["w", "x"], + fileobj: _GzipWritableFileobj | None = None, + 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, @@ -475,6 +660,78 @@ class TarFile: ) -> Self: ... @overload @classmethod + def gzopen( + cls, + fileobj: _GzipReadableFileobj, + *, + name: StrOrBytesPath | None, + mode: Literal["r"] = "r", + 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, + fileobj: _GzipWritableFileobj, + *, + name: StrOrBytesPath | None, + mode: Literal["w", "x"], + 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, + *, + 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["w", "x"], + fileobj: _Bz2WritableFileobj | None = None, + 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 | None, @@ -509,6 +766,61 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload + @classmethod + def bz2open( + cls, + fileobj: _Bz2ReadableFileobj, + *, + name: StrOrBytesPath | None, + mode: Literal["r"] = "r", + 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, + fileobj: _Bz2WritableFileobj, + *, + name: StrOrBytesPath | None, + mode: Literal["w", "x"], + 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, + mode: Literal["r", "w", "x"] = "r", + fileobj: IO[bytes] | None = None, + 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: ... + @overload @classmethod def xzopen( cls, @@ -526,6 +838,24 @@ class TarFile: debug: int | None = ..., errorlevel: int | None = ..., ) -> Self: ... + @overload + @classmethod + def xzopen( + cls, + fileobj: IO[bytes], + *, + name: StrOrBytesPath | None, + mode: Literal["r", "w", "x"] = "r", + 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]: ...