GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-58451: Add optional delete_on_close parameter to NamedTemporaryFile by Ev2geny · Pull Request #97015 · python/cpython

gh-58451: Add optional delete_on_close parameter to NamedTemporaryFile #97015

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.

Sign up for GitHub

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

Merged
zooba merged 26 commits into python:main from Ev2geny:fix-issue-14243
Oct 4, 2022

Uh oh!

There was an error while loading. Please reload this page.

Merged

gh-58451: Add optional delete_on_close parameter to NamedTemporaryFile #97015

Changes from 1 commit
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 Sep 21, 2022
c4cf39f
Based on the review from @eryksun the code and the documentation is u…
Ev2geny Sep 22, 2022
ac0b241
documentation is slightly corrected
Ev2geny Sep 22, 2022
384614f
minor documentation update
Ev2geny Sep 22, 2022
0e0b6ba
Update Doc/whatsnew/3.12.rst
Ev2geny Sep 22, 2022
cc81ab5
Deletion of file upon finalization is moved from _TemporaryFileWrappe…
Ev2geny Sep 23, 2022
5af6150
Some additions to Lib/test/test_tempfile.py
Ev2geny Sep 24, 2022
239354e
clearing of the files in the situation when delete and not delete_on_…
Ev2geny Sep 24, 2022
5de68c0
if statement is added to avoid errors, when testing. Not sure 100% is…
Ev2geny Sep 24, 2022
eef3439
Apply suggestions from code review
Ev2geny Sep 25, 2022
c9801ee
__del__ was defined twice in _TemporaryFileWrapper. Fixed now
Ev2geny Sep 25, 2022
6944ab2
_TemporaryFileCloser is returned to original state and the logic, whi…
Ev2geny Sep 25, 2022
44f0664
All delete operations are moved to the class _TemporaryFileCloser
Ev2geny Sep 25, 2022
1dfaf72
Minor update to comments
Ev2geny Sep 25, 2022
e54feb5
Whitespec fixes by patchcheck.py
Ev2geny Sep 25, 2022
d2d1119
Update Lib/tempfile.py
Ev2geny Sep 26, 2022
bd4b2dd
Update Lib/tempfile.py
Ev2geny Sep 26, 2022
29eeaff
Modified exception handling in NamedTemporaryFile
Ev2geny Sep 26, 2022
5306b6d
Wrapping at 80 characters is fixed
Ev2geny Sep 26, 2022
1c99fb3
Update Lib/tempfile.py
Ev2geny Oct 1, 2022
29b89d3
Documentation update, based on the feedback from @zooba
Ev2geny Oct 1, 2022
e586028
Minor PEP8 update based on the feedback from @zooba
Ev2geny Oct 1, 2022
3eceb45
Improving comments in the init test file, based on the feedback from …
Ev2geny Oct 1, 2022
892e87d
Updating of documentation
Ev2geny Oct 2, 2022
67996b2
Merge branch 'fix-issue-14243' of https://github.com/Ev2geny/cpython …
Ev2geny Oct 2, 2022
07b963e
Apply suggestions from code review
zooba Oct 4, 2022
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Prev Previous commit
Next Next commit
Improving comments in the init test file, based on the feedback from @…
…eryksun


Files changed:
      Lib/test/test_tempfile.py

Co-authored-by: Eryk Sun <[email protected]>
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@Ev2geny @eryksun
Ev2geny and eryksun authored Oct 1, 2022
commit 3eceb4549bc0529eddcacec4e0e54bc175d6f28f

There are no files selected for viewing

21 changes: 10 additions & 11 deletions 21 Lib/test/test_tempfile.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1043,8 +1043,8 @@ def test_context_man_not_del_on_close_if_delete_on_close_false(self):
os.rmdir(dir)

def test_context_man_ok_to_delete_manually(self):
# A NamedTemporaryFile can be deleted by a user before
# context manager comes to it. This will not generate an error
# In the case of delete=True, a NamedTemporaryFile can be manually
# deleted in a with-statement context without causing an error.
dir = tempfile.mkdtemp()
try:
with tempfile.NamedTemporaryFile(dir=dir,
Expand All @@ -1062,8 +1062,7 @@ def test_context_man_not_del_if_delete_false(self):
dir = tempfile.mkdtemp()
f_name = ""
try:
# setting delete_on_close = True to test, that this does not have
# an effect, if delete = False
# Test that delete_on_close=True has no effect if delete=False.
with tempfile.NamedTemporaryFile(dir=dir, delete=False,
delete_on_close=True) as f:
f.write(b'blat')
Expand All @@ -1075,8 +1074,8 @@ def test_context_man_not_del_if_delete_false(self):
os.rmdir(dir)

def test_del_by_finalizer(self):
# A NamedTemporaryFile is deleted by fanalizer in case delete = True
# delete_on_close = False and no context manager is used
# A NamedTemporaryFile is deleted when finalized in the case of
# delete=True, delete_on_close=False, and no with-statement is used.
def my_func(dir):
f = tempfile.NamedTemporaryFile(dir=dir, delete=True,
delete_on_close=False)
Expand All @@ -1085,7 +1084,7 @@ def my_func(dir):
# Testing extreme case, where the file is not explicitly closed
# f.close()
return tmp_name
# Making sure that Garbage Collector has finalized the file object
# Make sure that the garbage collector has finalized the file object.
gc.collect()
dir = tempfile.mkdtemp()
try:
Expand All @@ -1097,9 +1096,9 @@ def my_func(dir):
os.rmdir(dir)

def test_correct_finalizer_work_if_already_deleted(self):
# There should be No errors in case delete = True
# delete_on_close = False and no context manager is used, but file is
# deleted manually
# There should be no error in the case of delete=True,
# delete_on_close=False, no with-statement is used, and the file is
# deleted manually.
def my_func(dir)->str:
f = tempfile.NamedTemporaryFile(dir=dir, delete=True,
delete_on_close=False)
Expand All @@ -1108,7 +1107,7 @@ def my_func(dir)->str:
f.close()
os.unlink(tmp_name)
return tmp_name
# Making sure that Garbage Collector has finalized the file object
# Make sure that the garbage collector has finalized the file object.
gc.collect()

def test_bad_mode(self):
Expand Down
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.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.