Skip to content

gh-81954: Warn when ZipFile is closed with unwritten data#152354

Open
cmaloney wants to merge 1 commit into
python:mainfrom
cmaloney:zipfile_resourcewarning
Open

gh-81954: Warn when ZipFile is closed with unwritten data#152354
cmaloney wants to merge 1 commit into
python:mainfrom
cmaloney:zipfile_resourcewarning

Conversation

@cmaloney

@cmaloney cmaloney commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Bring zipfile.ZipFile into alignment with other buffered file writers like GzipFile and TextIOWrapper by emitting a ResourceWarning if there is unwritten data and it is closed implicitly.

ZipFile should be closed either by using it as a context manager or explicitly calling .close().

cc: @jaraco the _path/test_path fixtures have quite a few ZipFiles they don't close. For now I just blanket silenced, not sure your preferred upstream fix.

Bring `zipfile.ZipFile` into alignment with other buffered file writers
like `GzipFile` and `TextIOWrapper` by emitting a `ResourceWarning` if
there is unwritten data and it is closed implicitly.

ZipFile should be closed either by using it as a context manager or
explicitly calling `.close()`.
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33331784 | 📁 Comparing 5e16278 against main (1812162)

  🔍 Preview build  

2 files changed
± library/zipfile.html
± whatsnew/changelog.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant