[issue13585] Add contextlib.ContextStack

2012-01-02 Thread Meador Inge
Changes by Meador Inge : -- nosy: +meador.inge ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.pyth

[issue13585] Add contextlib.ContextStack

2011-12-22 Thread Nick Coghlan
Nick Coghlan added the comment: The comparison to Go's defer statement is interesting, though: ContextStack.register basically *is* the same as defer. While a nested with statement is a better option in Python, if we ignore that for the moment, you *could* write that simply copying example:

[issue13585] Add contextlib.ContextStack

2011-12-22 Thread Nick Coghlan
Nick Coghlan added the comment: ContextStack is intended to be a building block that makes it easy to compose context managers and other callbacks, not necessarily an API you'd regularly use directly. For example, given ContextStack (as currently implemented in contextlib2), it's trivial to w

[issue13585] Add contextlib.ContextStack

2011-12-22 Thread Antoine Pitrou
Antoine Pitrou 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 t

[issue13585] Add contextlib.ContextStack

2011-12-21 Thread Nick Coghlan
Nick Coghlan added the comment: Yeah, adding a "Recipes" section for contextlib2 is definitely on my to-do list (along with adding more examples in general). -- ___ Python tracker

[issue13585] Add contextlib.ContextStack

2011-12-21 Thread Raymond Hettinger
Raymond Hettinger added the comment: "I put my version up as a cookbook recipe: http://code.activestate.com/recipes/577981-cleanupmanager-for-with-statements/"; One other idea is to model what I've done with the itertools docs by adding a recipe section. I used it as an incubator for possibl

[issue13585] Add contextlib.ContextStack

2011-12-21 Thread Nick Coghlan
Nick Coghlan added the comment: Updated issue title to reflect what I'll eventually be proposing (once the ContextStack API has had a chance to mature on PyPI as part of contextlib2) -- title: Add contextlib.CleanupManager -> Add contextlib.ContextStack ___