@@ -59,3 +59,276 @@ SIM115.py:39:9: SIM115 Use a context manager for opening files
59
59
40 |
60
60
41 | # OK
61
61
|
62
+
63
+ SIM115 .py :80 :5 : SIM115 Use a context manager for opening files
64
+ |
65
+ 78 | import fileinput
66
+ 79 |
67
+ 80 | f = tempfile .NamedTemporaryFile ()
68
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM115
69
+ 81 | f = tempfile .TemporaryFile ()
70
+ 82 | f = tempfile .SpooledTemporaryFile ()
71
+ |
72
+
73
+ SIM115 .py :81 :5 : SIM115 Use a context manager for opening files
74
+ |
75
+ 80 | f = tempfile .NamedTemporaryFile ()
76
+ 81 | f = tempfile .TemporaryFile ()
77
+ | ^^^^^^^^^^^^^^^^^^^^^^ SIM115
78
+ 82 | f = tempfile .SpooledTemporaryFile ()
79
+ 83 | f = tarfile .open (" foo.tar" )
80
+ |
81
+
82
+ SIM115 .py :82 :5 : SIM115 Use a context manager for opening files
83
+ |
84
+ 80 | f = tempfile .NamedTemporaryFile ()
85
+ 81 | f = tempfile .TemporaryFile ()
86
+ 82 | f = tempfile .SpooledTemporaryFile ()
87
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM115
88
+ 83 | f = tarfile .open (" foo.tar" )
89
+ 84 | f = TarFile (" foo.tar" ).open ()
90
+ |
91
+
92
+ SIM115 .py :83 :5 : SIM115 Use a context manager for opening files
93
+ |
94
+ 81 | f = tempfile .TemporaryFile ()
95
+ 82 | f = tempfile .SpooledTemporaryFile ()
96
+ 83 | f = tarfile .open (" foo.tar" )
97
+ | ^^^^^^^^^^^^ SIM115
98
+ 84 | f = TarFile (" foo.tar" ).open ()
99
+ 85 | f = tarfile .TarFile (" foo.tar" ).open ()
100
+ |
101
+
102
+ SIM115 .py :84 :5 : SIM115 Use a context manager for opening files
103
+ |
104
+ 82 | f = tempfile .SpooledTemporaryFile ()
105
+ 83 | f = tarfile .open (" foo.tar" )
106
+ 84 | f = TarFile (" foo.tar" ).open ()
107
+ | ^^^^^^^^^^^^^^^^^^^^^^^ SIM115
108
+ 85 | f = tarfile .TarFile (" foo.tar" ).open ()
109
+ 86 | f = tarfile .TarFile ().open ()
110
+ |
111
+
112
+ SIM115 .py :85 :5 : SIM115 Use a context manager for opening files
113
+ |
114
+ 83 | f = tarfile .open (" foo.tar" )
115
+ 84 | f = TarFile (" foo.tar" ).open ()
116
+ 85 | f = tarfile .TarFile (" foo.tar" ).open ()
117
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM115
118
+ 86 | f = tarfile .TarFile ().open ()
119
+ 87 | f = zipfile .ZipFile (" foo.zip" ).open (" foo.txt" )
120
+ |
121
+
122
+ SIM115 .py :86 :5 : SIM115 Use a context manager for opening files
123
+ |
124
+ 84 | f = TarFile (" foo.tar" ).open ()
125
+ 85 | f = tarfile .TarFile (" foo.tar" ).open ()
126
+ 86 | f = tarfile .TarFile ().open ()
127
+ | ^^^^^^^^^^^^^^^^^^^^^^ SIM115
128
+ 87 | f = zipfile .ZipFile (" foo.zip" ).open (" foo.txt" )
129
+ 88 | f = io .open (" foo.txt" )
130
+ |
131
+
132
+ SIM115 .py :87 :5 : SIM115 Use a context manager for opening files
133
+ |
134
+ 85 | f = tarfile .TarFile (" foo.tar" ).open ()
135
+ 86 | f = tarfile .TarFile ().open ()
136
+ 87 | f = zipfile .ZipFile (" foo.zip" ).open (" foo.txt" )
137
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM115
138
+ 88 | f = io .open (" foo.txt" )
139
+ 89 | f = io .open_code (" foo.txt" )
140
+ |
141
+
142
+ SIM115 .py :88 :5 : SIM115 Use a context manager for opening files
143
+ |
144
+ 86 | f = tarfile .TarFile ().open ()
145
+ 87 | f = zipfile .ZipFile (" foo.zip" ).open (" foo.txt" )
146
+ 88 | f = io .open (" foo.txt" )
147
+ | ^^^^^^^ SIM115
148
+ 89 | f = io .open_code (" foo.txt" )
149
+ 90 | f = codecs .open (" foo.txt" )
150
+ |
151
+
152
+ SIM115 .py :89 :5 : SIM115 Use a context manager for opening files
153
+ |
154
+ 87 | f = zipfile .ZipFile (" foo.zip" ).open (" foo.txt" )
155
+ 88 | f = io .open (" foo.txt" )
156
+ 89 | f = io .open_code (" foo.txt" )
157
+ | ^^^^^^^^^^^^ SIM115
158
+ 90 | f = codecs .open (" foo.txt" )
159
+ 91 | f = bz2 .open (" foo.txt" )
160
+ |
161
+
162
+ SIM115 .py :90 :5 : SIM115 Use a context manager for opening files
163
+ |
164
+ 88 | f = io .open (" foo.txt" )
165
+ 89 | f = io .open_code (" foo.txt" )
166
+ 90 | f = codecs .open (" foo.txt" )
167
+ | ^^^^^^^^^^^ SIM115
168
+ 91 | f = bz2 .open (" foo.txt" )
169
+ 92 | f = gzip .open (" foo.txt" )
170
+ |
171
+
172
+ SIM115 .py :91 :5 : SIM115 Use a context manager for opening files
173
+ |
174
+ 89 | f = io .open_code (" foo.txt" )
175
+ 90 | f = codecs .open (" foo.txt" )
176
+ 91 | f = bz2 .open (" foo.txt" )
177
+ | ^^^^^^^^ SIM115
178
+ 92 | f = gzip .open (" foo.txt" )
179
+ 93 | f = dbm .open (" foo.db" )
180
+ |
181
+
182
+ SIM115 .py :92 :5 : SIM115 Use a context manager for opening files
183
+ |
184
+ 90 | f = codecs .open (" foo.txt" )
185
+ 91 | f = bz2 .open (" foo.txt" )
186
+ 92 | f = gzip .open (" foo.txt" )
187
+ | ^^^^^^^^^ SIM115
188
+ 93 | f = dbm .open (" foo.db" )
189
+ 94 | f = dbm .gnu .open (" foo.db" )
190
+ |
191
+
192
+ SIM115 .py :93 :5 : SIM115 Use a context manager for opening files
193
+ |
194
+ 91 | f = bz2 .open (" foo.txt" )
195
+ 92 | f = gzip .open (" foo.txt" )
196
+ 93 | f = dbm .open (" foo.db" )
197
+ | ^^^^^^^^ SIM115
198
+ 94 | f = dbm .gnu .open (" foo.db" )
199
+ 95 | f = dbm .ndbm .open (" foo.db" )
200
+ |
201
+
202
+ SIM115 .py :94 :5 : SIM115 Use a context manager for opening files
203
+ |
204
+ 92 | f = gzip .open (" foo.txt" )
205
+ 93 | f = dbm .open (" foo.db" )
206
+ 94 | f = dbm .gnu .open (" foo.db" )
207
+ | ^^^^^^^^^^^^ SIM115
208
+ 95 | f = dbm .ndbm .open (" foo.db" )
209
+ 96 | f = dbm .dumb .open (" foo.db" )
210
+ |
211
+
212
+ SIM115 .py :95 :5 : SIM115 Use a context manager for opening files
213
+ |
214
+ 93 | f = dbm .open (" foo.db" )
215
+ 94 | f = dbm .gnu .open (" foo.db" )
216
+ 95 | f = dbm .ndbm .open (" foo.db" )
217
+ | ^^^^^^^^^^^^^ SIM115
218
+ 96 | f = dbm .dumb .open (" foo.db" )
219
+ 97 | f = lzma .open (" foo.xz" )
220
+ |
221
+
222
+ SIM115 .py :96 :5 : SIM115 Use a context manager for opening files
223
+ |
224
+ 94 | f = dbm .gnu .open (" foo.db" )
225
+ 95 | f = dbm .ndbm .open (" foo.db" )
226
+ 96 | f = dbm .dumb .open (" foo.db" )
227
+ | ^^^^^^^^^^^^^ SIM115
228
+ 97 | f = lzma .open (" foo.xz" )
229
+ 98 | f = lzma .LZMAFile (" foo.xz" )
230
+ |
231
+
232
+ SIM115 .py :97 :5 : SIM115 Use a context manager for opening files
233
+ |
234
+ 95 | f = dbm .ndbm .open (" foo.db" )
235
+ 96 | f = dbm .dumb .open (" foo.db" )
236
+ 97 | f = lzma .open (" foo.xz" )
237
+ | ^^^^^^^^^ SIM115
238
+ 98 | f = lzma .LZMAFile (" foo.xz" )
239
+ 99 | f = shelve .open (" foo.db" )
240
+ |
241
+
242
+ SIM115 .py :98 :5 : SIM115 Use a context manager for opening files
243
+ |
244
+ 96 | f = dbm .dumb .open (" foo.db" )
245
+ 97 | f = lzma .open (" foo.xz" )
246
+ 98 | f = lzma .LZMAFile (" foo.xz" )
247
+ | ^^^^^^^^^^^^^ SIM115
248
+ 99 | f = shelve .open (" foo.db" )
249
+ 100 | f = tokenize .open (" foo.py" )
250
+ |
251
+
252
+ SIM115 .py :99 :5 : SIM115 Use a context manager for opening files
253
+ |
254
+ 97 | f = lzma .open (" foo.xz" )
255
+ 98 | f = lzma .LZMAFile (" foo.xz" )
256
+ 99 | f = shelve .open (" foo.db" )
257
+ | ^^^^^^^^^^^ SIM115
258
+ 100 | f = tokenize .open (" foo.py" )
259
+ 101 | f = wave .open (" foo.wav" )
260
+ |
261
+
262
+ SIM115 .py :100 :5 : SIM115 Use a context manager for opening files
263
+ |
264
+ 98 | f = lzma .LZMAFile (" foo.xz" )
265
+ 99 | f = shelve .open (" foo.db" )
266
+ 100 | f = tokenize .open (" foo.py" )
267
+ | ^^^^^^^^^^^^^ SIM115
268
+ 101 | f = wave .open (" foo.wav" )
269
+ 102 | f = tarfile .TarFile .taropen (" foo.tar" )
270
+ |
271
+
272
+ SIM115 .py :101 :5 : SIM115 Use a context manager for opening files
273
+ |
274
+ 99 | f = shelve .open (" foo.db" )
275
+ 100 | f = tokenize .open (" foo.py" )
276
+ 101 | f = wave .open (" foo.wav" )
277
+ | ^^^^^^^^^ SIM115
278
+ 102 | f = tarfile .TarFile .taropen (" foo.tar" )
279
+ 103 | f = fileinput .input (" foo.txt" )
280
+ |
281
+
282
+ SIM115 .py :102 :5 : SIM115 Use a context manager for opening files
283
+ |
284
+ 100 | f = tokenize .open (" foo.py" )
285
+ 101 | f = wave .open (" foo.wav" )
286
+ 102 | f = tarfile .TarFile .taropen (" foo.tar" )
287
+ | ^^^^^^^^^^^^^^^^^^^^^^^ SIM115
288
+ 103 | f = fileinput .input (" foo.txt" )
289
+ 104 | f = fileinput .FileInput (" foo.txt" )
290
+ |
291
+
292
+ SIM115 .py :103 :5 : SIM115 Use a context manager for opening files
293
+ |
294
+ 101 | f = wave .open (" foo.wav" )
295
+ 102 | f = tarfile .TarFile .taropen (" foo.tar" )
296
+ 103 | f = fileinput .input (" foo.txt" )
297
+ | ^^^^^^^^^^^^^^^ SIM115
298
+ 104 | f = fileinput .FileInput (" foo.txt" )
299
+ |
300
+
301
+ SIM115 .py :104 :5 : SIM115 Use a context manager for opening files
302
+ |
303
+ 102 | f = tarfile .TarFile .taropen (" foo.tar" )
304
+ 103 | f = fileinput .input (" foo.txt" )
305
+ 104 | f = fileinput .FileInput (" foo.txt" )
306
+ | ^^^^^^^^^^^^^^^^^^^ SIM115
307
+ 105 |
308
+ 106 | with contextlib .suppress (Exception ):
309
+ |
310
+
311
+ SIM115 .py :240 :9 : SIM115 Use a context manager for opening files
312
+ |
313
+ 238 | def aliased ():
314
+ 239 | from shelve import open as open_shelf
315
+ 240 | x = open_shelf (" foo.dbm" )
316
+ | ^^^^^^^^^^ SIM115
317
+ 241 | x .close ()
318
+ |
319
+
320
+ SIM115 .py :244 :9 : SIM115 Use a context manager for opening files
321
+ |
322
+ 243 | from tarfile import TarFile as TF
323
+ 244 | f = TF (" foo" ).open ()
324
+ | ^^^^^^^^^^^^^^ SIM115
325
+ 245 | f .close ()
326
+ |
327
+
328
+ SIM115 .py :257 :5 : SIM115 Use a context manager for opening files
329
+ |
330
+ 256 | # SIM115
331
+ 257 | f = dbm .sqlite3 .open (" foo.db" )
332
+ | ^^^^^^^^^^^^^^^^ SIM115
333
+ 258 | f .close ()
334
+ |
0 commit comments