[issue14243] tempfile.NamedTemporaryFile not particularly useful on Windows

Ethan Furman report at bugs.python.org
Wed Apr 7 19:43:49 EDT 2021


Ethan Furman <ethan at stoneleaf.us> added the comment:

I think the best solution, albeit slightly backwards incompatible, is to change NamedTemporaryFile such that if (and only if) it is being used as a context manager, the underlying file is not closed until the context manager ends.  This should be the default behavior with no new flags.

Since context managers are used for resource acquisition (`__enter__`) and cleanup (`__exit__`), having the resource disappear in the middle of the `with` block is counter-intuitive.

Given that closing a file in the middle of its CM seems like a very odd thing to do (one could just leave the CM and the file would close), do we need a deprecation period or can we just make the change?

----------
nosy: +ethan.furman
title: tempfile.NamedTemporaryFile not particularly useful on	Windows -> tempfile.NamedTemporaryFile not particularly useful on Windows

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue14243>
_______________________________________


More information about the Python-bugs-list mailing list