gh-154174: Support fresh ZipInfo objects in ZipFile.mkdir#154198
Open
zhangli091011 wants to merge 4 commits into
Open
gh-154174: Support fresh ZipInfo objects in ZipFile.mkdir#154198zhangli091011 wants to merge 4 commits into
zhangli091011 wants to merge 4 commits into
Conversation
danny0838
reviewed
Jul 21, 2026
Comment on lines
2532
to
2533
| zinfo.compress_size = 0 | ||
| zinfo.CRC = 0 |
Contributor
There was a problem hiding this comment.
Seems that these lines can now be removed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #154174.
ZipFile.mkdir()expected caller-suppliedZipInfoobjects to already have aCRCattribute, even though a freshZipInfodoes not initialize that attribute.Initialize
CRC,file_size, andcompress_sizeto zero for directory entries regardless of whethermkdir()receives a name or aZipInfo. Do not applyZipInfo._for_archive(), since caller-supplied timestamps, compression settings, comments, extra data, and permissions must be preserved consistently withwritestr().Tests verify that a fresh
ZipInfoworks and that caller metadata is preserved.Tests:
PCbuild\amd64\python_d.exe -m unittest -v test.test_zipfile.test_core.TestWithDirectory.test_mkdir test.test_zipfile.test_core.TestWithDirectory.test_mkdir_zipinfo_preserves_metadataPCbuild\amd64\python_d.exe -m test test_zipfile -v(590tests passed,5skipped)git diff --checkAI tooling assisted with repository analysis, implementation, and test preparation. The resulting changes and tests were reviewed and verified against a CPython debug build.
ZipFile.mkdir()on a newZipInfoobject gets an attribute error #154174