summaryrefslogtreecommitdiffstats
path: root/Python/instruction_sequence.c
diff options
context:
space:
mode:
authorCody Maloney <cmaloney@users.noreply.github.com>2025-03-13 10:20:05 (GMT)
committerGitHub <noreply@github.com>2025-03-13 10:20:05 (GMT)
commit93089c073661f5aa9f8cca574a3e223716728639 (patch)
treea0410a8883db29b4ccbc51b276936d9915bd6031 /Python/instruction_sequence.c
parentd12d8c50cddeb79f8d6e3d26a33f8f6b14bb4071 (diff)
downloadcpython-93089c073661f5aa9f8cca574a3e223716728639.zip
cpython-93089c073661f5aa9f8cca574a3e223716728639.tar.gz
cpython-93089c073661f5aa9f8cca574a3e223716728639.tar.bz2
gh-130806: Emit ResourceWarning if GzipFile unclosed (#130905)
This may indicate accidental data loss. Ways to make sure all data is written: 1. Use the [file-like object](https://docs.python.org/3/glossary.html#term-file-object) as a [“With Statement Context Manager”](https://docs.python.org/3/reference/datamodel.html#context-managers). - All objects which [inherit](https://docs.python.org/3/tutorial/classes.html#inheritance) from [IOBase](https://docs.python.org/3/library/io.html#io.IOBase) support this. - [`BufferedIOBase`](https://docs.python.org/3/library/io.html#io.BufferedIOBase), [`BufferedWriter`](https://docs.python.org/3/library/io.html#io.BufferedWriter), and [`GzipFile`](https://docs.python.org/3/library/gzip.html#gzip.GzipFile) all support this. - Ensures `.close()` is called in both exception and regular cases. 2. Ensure [`.close()`](https://docs.python.org/3/library/io.html#io.IOBase.close) is always called which flushes data before closing. 3. If the underlying stream need to be kept open, use [`.detach()`](https://docs.python.org/3/library/io.html#io.BufferedIOBase.detach) Since 3.12 flushing has been necessary in GzipFile (see gh-105808 which was a release blocker), this makes that more visible. Users have been encountering as they upgrade to 3.12 (ex. gh-129726). There are a number of cases of unclosed file-like objects being deleted in CPython libraries and the test suite. This issue includes resolving those cases where the new ResourceWarning is emitted. Co-authored-by: Victor Stinner <vstinner@python.org>
Diffstat (limited to 'Python/instruction_sequence.c')
0 files changed, 0 insertions, 0 deletions