@@ -55,7 +55,6 @@ def TemporaryFile(
55
55
prefix : Optional [AnyStr ] = ...,
56
56
dir : Optional [_DirT [AnyStr ]] = ...,
57
57
) -> IO [Any ]: ...
58
-
59
58
@overload
60
59
def NamedTemporaryFile (
61
60
mode : Literal ["r" , "w" , "a" , "x" , "r+" , "w+" , "a+" , "x+" , "rt" , "wt" , "at" , "xt" , "r+t" , "w+t" , "a+t" , "x+t" ],
@@ -93,17 +92,48 @@ def NamedTemporaryFile(
93
92
# It does not actually derive from IO[AnyStr], but it does implement the
94
93
# protocol.
95
94
class SpooledTemporaryFile (IO [AnyStr ]):
96
- def __init__ (self , max_size : int = ..., mode : str = ...,
97
- buffering : int = ..., encoding : Optional [str ] = ...,
98
- newline : Optional [str ] = ..., suffix : Optional [str ] = ...,
99
- prefix : Optional [str ] = ..., dir : Optional [str ] = ...
100
- ) -> None : ...
95
+ # bytes needs to go first, as default mode is to open as bytes
96
+ @overload
97
+ def __init__ (
98
+ self : SpooledTemporaryFile [bytes ],
99
+ max_size : int = ...,
100
+ mode : Literal ["rb" , "wb" , "ab" , "xb" , "r+b" , "w+b" , "a+b" , "x+b" ] = ...,
101
+ buffering : int = ...,
102
+ encoding : Optional [str ] = ...,
103
+ newline : Optional [str ] = ...,
104
+ suffix : Optional [str ] = ...,
105
+ prefix : Optional [str ] = ...,
106
+ dir : Optional [str ] = ...,
107
+ ) -> None : ...
108
+ @overload
109
+ def __init__ (
110
+ self : SpooledTemporaryFile [str ],
111
+ max_size : int = ...,
112
+ mode : Literal ["r" , "w" , "a" , "x" , "r+" , "w+" , "a+" , "x+" , "rt" , "wt" , "at" , "xt" , "r+t" , "w+t" , "a+t" , "x+t" ] = ...,
113
+ buffering : int = ...,
114
+ encoding : Optional [str ] = ...,
115
+ newline : Optional [str ] = ...,
116
+ suffix : Optional [str ] = ...,
117
+ prefix : Optional [str ] = ...,
118
+ dir : Optional [str ] = ...,
119
+ ) -> None : ...
120
+ @overload
121
+ def __init__ (
122
+ self ,
123
+ max_size : int = ...,
124
+ mode : str = ...,
125
+ buffering : int = ...,
126
+ encoding : Optional [str ] = ...,
127
+ newline : Optional [str ] = ...,
128
+ suffix : Optional [str ] = ...,
129
+ prefix : Optional [str ] = ...,
130
+ dir : Optional [str ] = ...,
131
+ ) -> None : ...
101
132
def rollover (self ) -> None : ...
102
133
def __enter__ (self : _S ) -> _S : ...
103
- def __exit__ (self , exc_type : Optional [Type [BaseException ]],
104
- exc_val : Optional [BaseException ],
105
- exc_tb : Optional [TracebackType ]) -> Optional [bool ]: ...
106
-
134
+ def __exit__ (
135
+ self , exc_type : Optional [Type [BaseException ]], exc_val : Optional [BaseException ], exc_tb : Optional [TracebackType ]
136
+ ) -> Optional [bool ]: ...
107
137
# These methods are copied from the abstract methods of IO, because
108
138
# SpooledTemporaryFile implements IO.
109
139
# See also https://github.com/python/typeshed/pull/2452#issuecomment-420657918.
@@ -127,25 +157,24 @@ class SpooledTemporaryFile(IO[AnyStr]):
127
157
128
158
class TemporaryDirectory (Generic [AnyStr ]):
129
159
name : str
130
- def __init__ (self , suffix : Optional [AnyStr ] = ..., prefix : Optional [AnyStr ] = ...,
131
- dir : Optional [_DirT [AnyStr ]] = ...) -> None : ...
160
+ def __init__ (
161
+ self , suffix : Optional [AnyStr ] = ..., prefix : Optional [AnyStr ] = ..., dir : Optional [_DirT [AnyStr ]] = ...
162
+ ) -> None : ...
132
163
def cleanup (self ) -> None : ...
133
164
def __enter__ (self ) -> AnyStr : ...
134
- def __exit__ (self , exc_type : Optional [ Type [ BaseException ]],
135
- exc_val : Optional [BaseException ],
136
- exc_tb : Optional [ TracebackType ] ) -> None : ...
165
+ def __exit__ (
166
+ self , exc_type : Optional [ Type [ BaseException ]], exc_val : Optional [BaseException ], exc_tb : Optional [ TracebackType ]
167
+ ) -> None : ...
137
168
138
- def mkstemp (suffix : Optional [AnyStr ] = ..., prefix : Optional [AnyStr ] = ..., dir : Optional [_DirT [AnyStr ]] = ...,
139
- text : bool = ...) -> Tuple [int , AnyStr ]: ...
169
+ def mkstemp (
170
+ suffix : Optional [AnyStr ] = ..., prefix : Optional [AnyStr ] = ..., dir : Optional [_DirT [AnyStr ]] = ..., text : bool = ...
171
+ ) -> Tuple [int , AnyStr ]: ...
140
172
@overload
141
173
def mkdtemp () -> str : ...
142
174
@overload
143
- def mkdtemp (suffix : Optional [AnyStr ] = ..., prefix : Optional [AnyStr ] = ...,
144
- dir : Optional [_DirT [AnyStr ]] = ...) -> AnyStr : ...
175
+ def mkdtemp (suffix : Optional [AnyStr ] = ..., prefix : Optional [AnyStr ] = ..., dir : Optional [_DirT [AnyStr ]] = ...) -> AnyStr : ...
145
176
def mktemp (suffix : Optional [AnyStr ] = ..., prefix : Optional [AnyStr ] = ..., dir : Optional [_DirT [AnyStr ]] = ...) -> AnyStr : ...
146
-
147
177
def gettempdirb () -> bytes : ...
148
178
def gettempprefixb () -> bytes : ...
149
-
150
179
def gettempdir () -> str : ...
151
180
def gettempprefix () -> str : ...
0 commit comments