is_zipfile() also accepts bytes paths (#7106)

Use a protocol for is_zipfile(), instead of IO
This commit is contained in:
Sebastian Rittau
2022-02-05 06:27:02 +01:00
committed by GitHub
parent 38d32a916c
commit 7179fee2d8

View File

@@ -1,6 +1,6 @@
import io
import sys
from _typeshed import Self, StrPath
from _typeshed import Self, StrOrBytesPath, StrPath
from os import PathLike
from types import TracebackType
from typing import IO, Any, Callable, Iterable, Iterator, Protocol, Sequence, overload
@@ -25,6 +25,12 @@ class _ZipStream(Protocol):
# def tell(self) -> int: ...
# def seek(self, __n: int) -> object: ...
# Stream shape as required by _EndRecData() and _EndRecData64().
class _SupportsReadSeekTell(Protocol):
def read(self, __n: int = ...) -> bytes: ...
def seek(self, __cookie: int, __whence: int) -> object: ...
def tell(self) -> int: ...
class _ClosableZipStream(_ZipStream, Protocol):
def close(self) -> object: ...
@@ -262,7 +268,7 @@ if sys.version_info >= (3, 8):
def __truediv__(self, add: StrPath) -> Path: ...
def is_zipfile(filename: StrPath | IO[bytes]) -> bool: ...
def is_zipfile(filename: StrOrBytesPath | _SupportsReadSeekTell) -> bool: ...
ZIP_STORED: int
ZIP_DEFLATED: int