@@ -103,12 +103,10 @@ PAX_NAME_FIELDS: set[str]
103
103
104
104
ENCODING : str
105
105
106
- _FileCreationModes : TypeAlias = Literal ["a" , "w" , "x" ]
107
-
108
106
@overload
109
107
def open (
110
108
name : StrOrBytesPath | None = None ,
111
- mode : str = "r" ,
109
+ mode : Literal [ "r" , "r:*" , "r:" , "r:gz" , "r:bz2" , "r:xz" ] = "r" ,
112
110
fileobj : IO [bytes ] | None = None ,
113
111
bufsize : int = 10240 ,
114
112
* ,
@@ -121,16 +119,124 @@ def open(
121
119
pax_headers : Mapping [str , str ] | None = ...,
122
120
debug : int | None = ...,
123
121
errorlevel : int | None = ...,
124
- compresslevel : int | None = ...,
122
+ ) -> TarFile : ...
123
+ @overload
124
+ def open (
125
+ name : StrOrBytesPath | None ,
126
+ mode : Literal ["x" , "x:" , "a" , "a:" , "w" , "w:" ],
127
+ fileobj : _Fileobj | None = None ,
128
+ bufsize : int = 10240 ,
129
+ * ,
130
+ format : int | None = ...,
131
+ tarinfo : type [TarInfo ] | None = ...,
132
+ dereference : bool | None = ...,
133
+ ignore_zeros : bool | None = ...,
134
+ encoding : str | None = ...,
135
+ errors : str = ...,
136
+ pax_headers : Mapping [str , str ] | None = ...,
137
+ debug : int | None = ...,
138
+ errorlevel : int | None = ...,
139
+ ) -> TarFile : ...
140
+ @overload
141
+ def open (
142
+ name : StrOrBytesPath | None = None ,
143
+ * ,
144
+ mode : Literal ["x" , "x:" , "a" , "a:" , "w" , "w:" ],
145
+ fileobj : _Fileobj | None = None ,
146
+ bufsize : int = 10240 ,
147
+ format : int | None = ...,
148
+ tarinfo : type [TarInfo ] | None = ...,
149
+ dereference : bool | None = ...,
150
+ ignore_zeros : bool | None = ...,
151
+ encoding : str | None = ...,
152
+ errors : str = ...,
153
+ pax_headers : Mapping [str , str ] | None = ...,
154
+ debug : int | None = ...,
155
+ errorlevel : int | None = ...,
156
+ ) -> TarFile : ...
157
+ @overload
158
+ def open (
159
+ name : StrOrBytesPath | None ,
160
+ mode : Literal ["x:gz" , "x:bz2" , "w:gz" , "w:bz2" ],
161
+ fileobj : _Fileobj | None = None ,
162
+ bufsize : int = 10240 ,
163
+ * ,
164
+ format : int | None = ...,
165
+ tarinfo : type [TarInfo ] | None = ...,
166
+ dereference : bool | None = ...,
167
+ ignore_zeros : bool | None = ...,
168
+ encoding : str | None = ...,
169
+ errors : str = ...,
170
+ pax_headers : Mapping [str , str ] | None = ...,
171
+ debug : int | None = ...,
172
+ errorlevel : int | None = ...,
173
+ compresslevel : int = 9 ,
174
+ ) -> TarFile : ...
175
+ @overload
176
+ def open (
177
+ name : StrOrBytesPath | None = None ,
178
+ * ,
179
+ mode : Literal ["x:gz" , "x:bz2" , "w:gz" , "w:bz2" ],
180
+ fileobj : _Fileobj | None = None ,
181
+ bufsize : int = 10240 ,
182
+ format : int | None = ...,
183
+ tarinfo : type [TarInfo ] | None = ...,
184
+ dereference : bool | None = ...,
185
+ ignore_zeros : bool | None = ...,
186
+ encoding : str | None = ...,
187
+ errors : str = ...,
188
+ pax_headers : Mapping [str , str ] | None = ...,
189
+ debug : int | None = ...,
190
+ errorlevel : int | None = ...,
191
+ compresslevel : int = 9 ,
192
+ ) -> TarFile : ...
193
+ @overload
194
+ def open (
195
+ name : StrOrBytesPath | None ,
196
+ mode : Literal ["x:xz" , "w:xz" ],
197
+ fileobj : _Fileobj | None = None ,
198
+ bufsize : int = 10240 ,
199
+ * ,
200
+ format : int | None = ...,
201
+ tarinfo : type [TarInfo ] | None = ...,
202
+ dereference : bool | None = ...,
203
+ ignore_zeros : bool | None = ...,
204
+ encoding : str | None = ...,
205
+ errors : str = ...,
206
+ pax_headers : Mapping [str , str ] | None = ...,
207
+ debug : int | None = ...,
208
+ errorlevel : int | None = ...,
125
209
preset : Literal [0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] | None = ...,
126
210
) -> TarFile : ...
127
211
@overload
128
212
def open (
129
213
name : StrOrBytesPath | None = None ,
130
- mode : _FileCreationModes = ...,
214
+ * ,
215
+ mode : Literal ["x:xz" , "w:xz" ],
131
216
fileobj : _Fileobj | None = None ,
132
217
bufsize : int = 10240 ,
218
+ format : int | None = ...,
219
+ tarinfo : type [TarInfo ] | None = ...,
220
+ dereference : bool | None = ...,
221
+ ignore_zeros : bool | None = ...,
222
+ encoding : str | None = ...,
223
+ errors : str = ...,
224
+ pax_headers : Mapping [str , str ] | None = ...,
225
+ debug : int | None = ...,
226
+ errorlevel : int | None = ...,
227
+ preset : Literal [0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] | None = ...,
228
+ ) -> TarFile : ...
229
+
230
+ # TODO: Temporary fallback for modes containing pipe characters. These don't
231
+ # work with mypy 1.10, but this should be fixed with mypy 1.11.
232
+ # https://github.com/python/typeshed/issues/12182
233
+ @overload
234
+ def open (
235
+ name : StrOrBytesPath | None = None ,
133
236
* ,
237
+ mode : str ,
238
+ fileobj : IO [bytes ] | None = None ,
239
+ bufsize : int = 10240 ,
134
240
format : int | None = ...,
135
241
tarinfo : type [TarInfo ] | None = ...,
136
242
dereference : bool | None = ...,
@@ -140,7 +246,6 @@ def open(
140
246
pax_headers : Mapping [str , str ] | None = ...,
141
247
debug : int | None = ...,
142
248
errorlevel : int | None = ...,
143
- compresslevel : int | None = ...,
144
249
preset : int | None = ...,
145
250
) -> TarFile : ...
146
251
0 commit comments