diff options
Diffstat (limited to 'Lib/importlib/_common.py')
-rw-r--r-- | Lib/importlib/_common.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/Lib/importlib/_common.py b/Lib/importlib/_common.py index 549fee3..84144c0 100644 --- a/Lib/importlib/_common.py +++ b/Lib/importlib/_common.py @@ -80,7 +80,10 @@ def from_package(package): @contextlib.contextmanager -def _tempfile(reader, suffix=''): +def _tempfile(reader, suffix='', + # gh-93353: Keep a reference to call os.remove() in late Python + # finalization. + *, _os_remove=os.remove): # Not using tempfile.NamedTemporaryFile as it leads to deeper 'try' # blocks due to the need to close the temporary file to work on Windows # properly. @@ -92,7 +95,7 @@ def _tempfile(reader, suffix=''): yield pathlib.Path(raw_path) finally: try: - os.remove(raw_path) + _os_remove(raw_path) except FileNotFoundError: pass |