Commit 8849642
committed
fix(stream_io): Finalize temporary files correctly on
The temporary file finalizer's check that the file is not already closed
was causing the upload to be skipped if the stream was used as a context
manager without an explicit call to .close(), because CPython's
implementation of .__exit__() for NamedTemporaryFile objects closes
the underlying file before calling the wrapper's own .close() method.
After changing to `weakref.finalize` in commit 3fd7f1e, uploading
temporary files became inherently idempotent, so the check that the file
is not already closed is no longer necessary anyway.
This change deletes that check.
Furthermore, changes to the NamedTemporaryFile implementation with the
addition of its delete_on_close parameter in Python 3.12
(python/cpython#97015) make its .__exit__() method no longer call
its .close() method at all, so this change also embeds the finalizer
as a hook in a wrapper around both .close() and .__exit__() separately.__exit__
1 parent c46ed35 commit 8849642
3 files changed
+53
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
8 | 23 | | |
9 | 24 | | |
10 | 25 | | |
| |||
265 | 280 | | |
266 | 281 | | |
267 | 282 | | |
268 | | - | |
| 283 | + | |
| 284 | + | |
269 | 285 | | |
270 | 286 | | |
271 | 287 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1053 | 1053 | | |
1054 | 1054 | | |
1055 | 1055 | | |
1056 | | - | |
1057 | | - | |
1058 | | - | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
1059 | 1059 | | |
1060 | 1060 | | |
1061 | 1061 | | |
| |||
1077 | 1077 | | |
1078 | 1078 | | |
1079 | 1079 | | |
1080 | | - | |
1081 | | - | |
1082 | | - | |
1083 | | - | |
1084 | | - | |
1085 | | - | |
1086 | | - | |
1087 | | - | |
1088 | | - | |
1089 | | - | |
1090 | | - | |
1091 | 1080 | | |
1092 | 1081 | | |
1093 | 1082 | | |
| |||
1281 | 1270 | | |
1282 | 1271 | | |
1283 | 1272 | | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
1284 | 1276 | | |
1285 | 1277 | | |
1286 | 1278 | | |
| |||
1291 | 1283 | | |
1292 | 1284 | | |
1293 | 1285 | | |
1294 | | - | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
1295 | 1315 | | |
1296 | 1316 | | |
1297 | 1317 | | |
| |||
0 commit comments