-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
bpo-40105: Truncating file if opened in append mode. #19337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA). CLA MissingOur records indicate the following people have not signed the CLA: For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. If you have recently signed the CLA, please wait at least one business day You can check yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good! Just a couple of minor comments regarding the test.
Lib/test/test_zipfile.py
Outdated
with zipfile.ZipFile(TESTFN,mode="a") as zipf: | ||
zipf.comment = b"shorter comment" | ||
zipf.comment = one_byte_shorter_comment | ||
self.assertEqual(original_zip_size, os.path.getsize(TESTFN) + 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing for the precise size is too restrictive IMO. It would be better to just test that the size was reduced. That would also allow keeping the existing comments.
Lib/test/test_zipfile.py
Outdated
original_comment = b"original comment that's longer" | ||
one_byte_shorter_comment = original_comment[:-1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO extracting these to variables makes the test code harder to understand rather than easier. I suggest undoing this change.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
I have made the requested changes; please review again. |
Thanks for making the requested changes! @taleinat: please review the changes made to this pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
GH-22436 is a backport of this pull request to the 3.9 branch. |
GH-22437 is a backport of this pull request to the 3.8 branch. |
GH-22439 is a backport of this pull request to the 3.9 branch. |
Implemented a test for this behaviour.
If we just
truncate
the test fails forUnseekable
file types. In current implementation, those type of files can't be opened in the append ('a'
) mode anyway, so we could make a check for that in the future.https://bugs.python.org/issue40105