From 995e83ba2a4ac6eb0ae9f0404c01d850fd4a1985 Mon Sep 17 00:00:00 2001 From: Shantanu Date: Sun, 19 Jan 2020 04:52:08 -0600 Subject: [PATCH] zipfile: fix various stubs (#3621) Found using new stub checking script --- stdlib/2and3/zipfile.pyi | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/stdlib/2and3/zipfile.pyi b/stdlib/2and3/zipfile.pyi index 9a449f4ef..36fbc9cf8 100644 --- a/stdlib/2and3/zipfile.pyi +++ b/stdlib/2and3/zipfile.pyi @@ -1,6 +1,6 @@ # Stubs for zipfile -from typing import Callable, Dict, IO, Iterable, Iterator, List, Optional, Text, Tuple, Type, Union, Sequence, Pattern +from typing import Any, Callable, Dict, IO, Iterable, Iterator, List, Optional, Protocol, Text, Tuple, Type, Union, Sequence, Pattern from types import TracebackType import io import os @@ -58,6 +58,9 @@ class ZipExtFile(io.BufferedIOBase): def peek(self, n: int = ...) -> bytes: ... def read1(self, n: Optional[int]) -> bytes: ... # type: ignore +class _Writer(Protocol): + def write(self, __s: str) -> Any: ... + class ZipFile: filename: Optional[Text] debug: int @@ -103,12 +106,20 @@ class ZipFile: def extractall( self, path: Optional[_Path] = ..., members: Optional[Iterable[Text]] = ..., pwd: Optional[bytes] = ... ) -> None: ... - def printdir(self) -> None: ... + if sys.version_info >= (3,): + def printdir(self, file: Optional[_Writer] = ...) -> None: ... + else: + def printdir(self) -> None: ... def setpassword(self, pwd: bytes) -> None: ... def read(self, name: _SZI, pwd: Optional[bytes] = ...) -> bytes: ... def testzip(self) -> Optional[str]: ... - def write(self, filename: _Path, arcname: Optional[_Path] = ..., compress_type: Optional[int] = ...) -> None: ... - if sys.version_info >= (3,): + if sys.version_info >= (3, 7): + def write(self, filename: _Path, arcname: Optional[_Path] = ..., compress_type: Optional[int] = ..., compresslevel: Optional[int] = ...) -> None: ... + else: + def write(self, filename: _Path, arcname: Optional[_Path] = ..., compress_type: Optional[int] = ...) -> None: ... + if sys.version_info >= (3, 7): + def writestr(self, zinfo_or_arcname: _SZI, data: Union[bytes, str], compress_type: Optional[int] = ..., compresslevel: Optional[int] = ...) -> None: ... + elif sys.version_info >= (3,): def writestr(self, zinfo_or_arcname: _SZI, data: Union[bytes, str], compress_type: Optional[int] = ...) -> None: ... else: def writestr(self, zinfo_or_arcname: _SZI, bytes: bytes, compress_type: Optional[int] = ...) -> None: ...