On 3 February 2012 15:09, Yury Selivanov
<yselivanov.ml@gmail.com> wrote:
Hello,
With the removal of "contextlib.nested" in python 3.2 nothing was introduced to replace it. However, I found it pretty useful, despite the fact that it had its own quirks. These quirks can (at least partially) be addressed by allowing unpacking syntax in the context manager.
Consider the following snipped of code:
ctxs = ()
if args.profile:
ctxs += (ApplicationProfilerContext(),)
if args.logging:
ctxs += (ApplicationLoggingContext(),)
with *ctxs:
Application.run()
Well, I quite like this syntax and it does allow you to do something not currently easily possible:
with *ctxs as tuple_of_results:
...
The use case is reasonably obscure however, and should this be possible:
with *ctx, other as tuple_of_results, another:
...
Michael
As of now, without "nested" we have either option of reimplementing it, or to write lots of ugly code with nested 'try..except's. So the feature was taken out, but nothing replaced it.
What do you think guys?
Thanks,
Yury
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
http://mail.python.org/mailman/listinfo/python-ideas