mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-09 05:24:52 +08:00
Accurate overloads for ZipFile.__init__ (#12119)
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
This commit is contained in:
@@ -94,6 +94,20 @@ class ZipExtFile(io.BufferedIOBase):
|
||||
class _Writer(Protocol):
|
||||
def write(self, s: str, /) -> object: ...
|
||||
|
||||
class _ZipReadable(Protocol):
|
||||
def seek(self, offset: int, whence: int = 0, /) -> int: ...
|
||||
def read(self, n: int = -1, /) -> bytes: ...
|
||||
|
||||
class _ZipTellable(Protocol):
|
||||
def tell(self) -> int: ...
|
||||
|
||||
class _ZipReadableTellable(_ZipReadable, _ZipTellable, Protocol): ...
|
||||
|
||||
class _ZipWritable(Protocol):
|
||||
def flush(self) -> None: ...
|
||||
def close(self) -> None: ...
|
||||
def write(self, b: bytes, /) -> int: ...
|
||||
|
||||
class ZipFile:
|
||||
filename: str | None
|
||||
debug: int
|
||||
@@ -106,24 +120,50 @@ class ZipFile:
|
||||
compresslevel: int | None # undocumented
|
||||
mode: _ZipFileMode # undocumented
|
||||
pwd: bytes | None # undocumented
|
||||
# metadata_encoding is new in 3.11
|
||||
if sys.version_info >= (3, 11):
|
||||
@overload
|
||||
def __init__(
|
||||
self,
|
||||
file: StrPath | IO[bytes],
|
||||
mode: _ZipFileMode = "r",
|
||||
compression: int = 0,
|
||||
allowZip64: bool = True,
|
||||
compresslevel: int | None = None,
|
||||
*,
|
||||
strict_timestamps: bool = True,
|
||||
metadata_encoding: str | None = None,
|
||||
) -> None: ...
|
||||
# metadata_encoding is only allowed for read mode
|
||||
@overload
|
||||
def __init__(
|
||||
self,
|
||||
file: StrPath | _ZipReadable,
|
||||
mode: Literal["r"] = "r",
|
||||
compression: int = 0,
|
||||
allowZip64: bool = True,
|
||||
compresslevel: int | None = None,
|
||||
*,
|
||||
strict_timestamps: bool = True,
|
||||
metadata_encoding: str | None,
|
||||
metadata_encoding: str | None = None,
|
||||
) -> None: ...
|
||||
@overload
|
||||
def __init__(
|
||||
self,
|
||||
file: StrPath | IO[bytes],
|
||||
mode: _ZipFileMode = "r",
|
||||
file: StrPath | _ZipWritable,
|
||||
mode: Literal["w", "x"] = ...,
|
||||
compression: int = 0,
|
||||
allowZip64: bool = True,
|
||||
compresslevel: int | None = None,
|
||||
*,
|
||||
strict_timestamps: bool = True,
|
||||
metadata_encoding: None = None,
|
||||
) -> None: ...
|
||||
@overload
|
||||
def __init__(
|
||||
self,
|
||||
file: StrPath | _ZipReadableTellable,
|
||||
mode: Literal["a"] = ...,
|
||||
compression: int = 0,
|
||||
allowZip64: bool = True,
|
||||
compresslevel: int | None = None,
|
||||
@@ -132,6 +172,7 @@ class ZipFile:
|
||||
metadata_encoding: None = None,
|
||||
) -> None: ...
|
||||
else:
|
||||
@overload
|
||||
def __init__(
|
||||
self,
|
||||
file: StrPath | IO[bytes],
|
||||
@@ -142,6 +183,39 @@ class ZipFile:
|
||||
*,
|
||||
strict_timestamps: bool = True,
|
||||
) -> None: ...
|
||||
@overload
|
||||
def __init__(
|
||||
self,
|
||||
file: StrPath | _ZipReadable,
|
||||
mode: Literal["r"] = "r",
|
||||
compression: int = 0,
|
||||
allowZip64: bool = True,
|
||||
compresslevel: int | None = None,
|
||||
*,
|
||||
strict_timestamps: bool = True,
|
||||
) -> None: ...
|
||||
@overload
|
||||
def __init__(
|
||||
self,
|
||||
file: StrPath | _ZipWritable,
|
||||
mode: Literal["w", "x"] = ...,
|
||||
compression: int = 0,
|
||||
allowZip64: bool = True,
|
||||
compresslevel: int | None = None,
|
||||
*,
|
||||
strict_timestamps: bool = True,
|
||||
) -> None: ...
|
||||
@overload
|
||||
def __init__(
|
||||
self,
|
||||
file: StrPath | _ZipReadableTellable,
|
||||
mode: Literal["a"] = ...,
|
||||
compression: int = 0,
|
||||
allowZip64: bool = True,
|
||||
compresslevel: int | None = None,
|
||||
*,
|
||||
strict_timestamps: bool = True,
|
||||
) -> None: ...
|
||||
|
||||
def __enter__(self) -> Self: ...
|
||||
def __exit__(
|
||||
|
||||
Reference in New Issue
Block a user