[issue5178] Add content manager for temporary directory

Nick Coghlan report at bugs.python.org
Sat Feb 7 22:31:12 CET 2009


Nick Coghlan <ncoghlan at gmail.com> added the comment:

A __del__ method is definitely desirable (tempfile._TemporaryFileWrapper
gives an example of how to cache the relevant globals on the class
object to avoid attempting calls to None during interpreter shutdown).

The new examples are good, but may give the misleading impression that
TemporaryFile can't be used as a context manager (it can, and the file
will be closed at the end of the with statement). A second file example
showing it being used as a context manager would probably be helpful.

There is also at least one existing contextlib based temp_dir context
managers that could be replaced given the addition of this (i.e. in
test_cmd_line_script.py, "test_dir" could be changed to a class that
inherits from tempfile.TemporaryDirectory and overrides __enter__ to
invoke realname() on the directory name).

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5178>
_______________________________________


More information about the Python-bugs-list mailing list