Original file line numberDiff line numberDiff line change@@ -67,7 +67,10 @@ def from_package(package):
70-def_tempfile(reader, suffix=''):
70+def_tempfile(reader, suffix='',
71+# gh-93353: Keep a reference to call os.remove() in late Python
72+# finalization.
73+*, _os_remove=os.remove):
7174# Not using tempfile.NamedTemporaryFile as it leads to deeper 'try'
7275# blocks due to the need to close the temporary file to work on Windows
7376# properly.
@@ -81,7 +84,7 @@ def _tempfile(reader, suffix=''):
8184yieldpathlib.Path(raw_path)
8285finally:
8386try:
84-os.remove(raw_path)
87+_os_remove(raw_path)
8588exceptFileNotFoundError:
8689pass
8790