[issue2021] Turn NamedTemporaryFile into a context manager

Nick Coghlan report at bugs.python.org
Sat Feb 9 16:32:02 CET 2008


Nick Coghlan added the comment:

I've changed the issue type from rfe to behaviour. NamedTemporaryFile
actually provides __enter__ and __exit__ methods in 2.5, they just don't
work (it tries to use the methods from the underlying file object
directly which turns out to be a doomed exercise for a couple of
different reasons).

Fixed on the trunk in r60695. Leaving issue as pending until the
NamedTemporaryFile fix is backported to 2.5 (or we decide not to
backport it).

P.S. Alexander's patch worked as written, but in figuring out *why* it
worked I ended up moving things around a bit (main change was to only
override __exit__ when it was actually necessary to do so) and adding
some more test cases (e.g. to also cover 2.6's new SpooledTemporaryFile).

----------
resolution:  -> fixed
status: open -> pending
type: rfe -> behavior

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2021>
__________________________________


More information about the Python-bugs-list mailing list