-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
gh-58451: Add optional delete_on_close parameter to NamedTemporaryFile #97015
Merged
Merged
Changes from 23 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
3df957c
Brought the same changes as in now closed PR 22431, but to the latest…
Ev2geny c4cf39f
Based on the review from @eryksun the code and the documentation is u…
Ev2geny ac0b241
documentation is slightly corrected
Ev2geny 384614f
minor documentation update
Ev2geny 0e0b6ba
Update Doc/whatsnew/3.12.rst
Ev2geny cc81ab5
Deletion of file upon finalization is moved from _TemporaryFileWrappe…
Ev2geny 5af6150
Some additions to Lib/test/test_tempfile.py
Ev2geny 239354e
clearing of the files in the situation when delete and not delete_on_…
Ev2geny 5de68c0
if statement is added to avoid errors, when testing. Not sure 100% is…
Ev2geny eef3439
Apply suggestions from code review
Ev2geny c9801ee
__del__ was defined twice in _TemporaryFileWrapper. Fixed now
Ev2geny 6944ab2
_TemporaryFileCloser is returned to original state and the logic, whi…
Ev2geny 44f0664
All delete operations are moved to the class _TemporaryFileCloser
Ev2geny 1dfaf72
Minor update to comments
Ev2geny e54feb5
Whitespec fixes by patchcheck.py
Ev2geny d2d1119
Update Lib/tempfile.py
Ev2geny bd4b2dd
Update Lib/tempfile.py
Ev2geny 29eeaff
Modified exception handling in NamedTemporaryFile
Ev2geny 5306b6d
Wrapping at 80 characters is fixed
Ev2geny 1c99fb3
Update Lib/tempfile.py
Ev2geny 29b89d3
Documentation update, based on the feedback from @zooba
Ev2geny e586028
Minor PEP8 update based on the feedback from @zooba
Ev2geny 3eceb45
Improving comments in the init test file, based on the feedback from …
Ev2geny 892e87d
Updating of documentation
Ev2geny 67996b2
Merge branch 'fix-issue-14243' of https://github.com/Ev2geny/cpython …
Ev2geny 07b963e
Apply suggestions from code review
zooba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
1 change: 1 addition & 0 deletions
1
Misc/NEWS.d/next/Library/2020-09-28-04-56-04.bpo-14243.YECnxv.rst
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The :class:`tempfile.NamedTemporaryFile` function has a new optional parameter *delete_on_close* |
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.
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.
I know this line was here before, but it doesn't make any sense to me. Should we mention this somewhere else?
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.
@eryksun , I think zooba talks about the line "(on Unix, the directory entry is not unlinked)." What do you think, does it make scene to move it somewhere else?
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.
On POSIX, a file created by
TemoraryFile()
does not have a visible name in the filesystem. The implementation tries to use theO_TMPFILE
flag if it's supported (Linux 3.11+), which creates an anonymous file. IfO_TMPFILE
isn't supported, the file is created with a unique name, and then it's immediately unlinked while the file descriptor is still open.On Windows,
TemporaryFile
is aliased toNamedTemporaryFile
. There isn't a compelling reason for this decision. It's fine to delete a file that's opened with theO_TEMPORARY
flag. On Windows 10 and 11, if it's on an NTFS filesystem, the file gets unlinked immediately. Prior to Windows 10, or on filesystems other than NTFS, the file is deleted but not unlinked. In the latter state, a file has a visible entry in the directory, but it can't be opened again for any access, and it gets unlinked as soon as the last handle to it is closed.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.
@eryksun , thanks for explanation. So, would you agree, that the statement on Unix, the directory entry is not unlinked does not really make too much scene the way it is written now? Would it be better to either remove it completely or to put a broader explanation, similar to what you provided?
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.
It's in the context of clarifying that
NamedTemporaryFile()
acts "exactly" likeTemporaryFile()
. In that context it makes sense. But I'd prefer that the first sentence and the two bullet points were replaced with something like the following: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.
I have now placed the statement about unlinking on Unix to a different place and slightly reworked it to make a reference to TemporaryFile(), without which I agree it was a bit confusing.
I have also implemented rewording from @eryksun