@@ -2,7 +2,8 @@ import io
2
2
import sys
3
3
from _typeshed import StrPath
4
4
from types import TracebackType
5
- from typing import IO , Any , Callable , Dict , Iterable , Iterator , List , Optional , Protocol , Sequence , Tuple , Type , Union
5
+ from typing import IO , Callable , Dict , Iterable , Iterator , List , Optional , Protocol , Sequence , Tuple , Type , Union , overload
6
+ from typing_extensions import Literal
6
7
7
8
_DateTuple = Tuple [int , int , int , int , int , int ]
8
9
@@ -13,6 +14,16 @@ error = BadZipfile
13
14
14
15
class LargeZipFile (Exception ): ...
15
16
17
+ class _ZipStream (Protocol ):
18
+ def read (self , __n : int ) -> bytes : ...
19
+ # The following methods are optional:
20
+ # def seekable(self) -> bool: ...
21
+ # def tell(self) -> int: ...
22
+ # def seek(self, __n: int) -> object: ...
23
+
24
+ class _ClosableZipStream (_ZipStream , Protocol ):
25
+ def close (self ) -> object : ...
26
+
16
27
class ZipExtFile (io .BufferedIOBase ):
17
28
MAX_N : int = ...
18
29
MIN_READ_SIZE : int = ...
@@ -24,13 +35,48 @@ class ZipExtFile(io.BufferedIOBase):
24
35
mode : str
25
36
name : str
26
37
if sys .version_info >= (3 , 7 ):
38
+ @overload
27
39
def __init__ (
28
- self , fileobj : IO [bytes ], mode : str , zipinfo : ZipInfo , pwd : Optional [bytes ] = ..., close_fileobj : bool = ...
40
+ self , fileobj : _ClosableZipStream , mode : str , zipinfo : ZipInfo , pwd : Optional [bytes ], close_fileobj : Literal [True ]
41
+ ) -> None : ...
42
+ @overload
43
+ def __init__ (
44
+ self ,
45
+ fileobj : _ClosableZipStream ,
46
+ mode : str ,
47
+ zipinfo : ZipInfo ,
48
+ pwd : Optional [bytes ] = ...,
49
+ * ,
50
+ close_fileobj : Literal [True ],
51
+ ) -> None : ...
52
+ @overload
53
+ def __init__ (
54
+ self , fileobj : _ZipStream , mode : str , zipinfo : ZipInfo , pwd : Optional [bytes ] = ..., close_fileobj : bool = ...
29
55
) -> None : ...
30
56
else :
57
+ @overload
58
+ def __init__ (
59
+ self ,
60
+ fileobj : _ClosableZipStream ,
61
+ mode : str ,
62
+ zipinfo : ZipInfo ,
63
+ decrypter : Optional [Callable [[Sequence [int ]], bytes ]],
64
+ close_fileobj : Literal [True ],
65
+ ) -> None : ...
66
+ @overload
67
+ def __init__ (
68
+ self ,
69
+ fileobj : _ClosableZipStream ,
70
+ mode : str ,
71
+ zipinfo : ZipInfo ,
72
+ decrypter : Optional [Callable [[Sequence [int ]], bytes ]] = ...,
73
+ * ,
74
+ close_fileobj : Literal [True ],
75
+ ) -> None : ...
76
+ @overload
31
77
def __init__ (
32
78
self ,
33
- fileobj : IO [ bytes ] ,
79
+ fileobj : _ZipStream ,
34
80
mode : str ,
35
81
zipinfo : ZipInfo ,
36
82
decrypter : Optional [Callable [[Sequence [int ]], bytes ]] = ...,
@@ -43,7 +89,7 @@ class ZipExtFile(io.BufferedIOBase):
43
89
def read1 (self , n : Optional [int ]) -> bytes : ... # type: ignore
44
90
45
91
class _Writer (Protocol ):
46
- def write (self , __s : str ) -> Any : ...
92
+ def write (self , __s : str ) -> object : ...
47
93
48
94
class ZipFile :
49
95
filename : Optional [str ]
0 commit comments