[issue13585] Add contextlib.ContextStack

Antoine Pitrou report at bugs.python.org
Thu Dec 22 09:47:13 CET 2011


Antoine Pitrou <pitrou at free.fr> added the comment:

>     with ContextStack() as stack:
>         files = [stack.enter_context(open(fname)) for fname in filenames]

I find this a bit distasteful. Cleaning up resources now needs something called a "ContextStack" and an "enter_context" method call. There's a bit too much terminology, and it looks like a poor man's equivalent of Go's "defer" statement:
http://blog.golang.org/2010/08/defer-panic-and-recover.html

I like unittest's addCleanup mechanism better.

----------
nosy: +pitrou

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


More information about the Python-bugs-list mailing list