[Python-ideas] with-statement syntactic quirk

Yuval Greenfield ubershmekel at gmail.com
Mon Nov 5 09:10:41 CET 2012

On Sun, Nov 4, 2012 at 5:41 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:

> Yep. You can also do some pretty interesting things with ExitStack
> because of the pop_all() operation (which moves all of the registered
> operations to a *new* ExitStack instance).
> I wrote up a few of the motivating use cases as examples and recipes
> in the 3.3 docs:
> http://docs.python.org/3/library/contextlib#examples-and-recipes
> I hope to see more interesting uses over time as more people explore
> the possibilities of a dynamic tool for composing context managers
> without needing to worry about the messy details of unwinding them
> correctly (ExitStack.__exit__ is by far the most complicated aspect of
> the implementation).
> Cheers,
> Nick.
Pretty interesting things indeed. It does look like the concept is very
powerful. If I were to design a language I might have just given every
function an optional ExitStack. I.e. an explicit, dynamic, introspectable
version of defer.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20121105/43a2c713/attachment.html>

More information about the Python-ideas mailing list