On 3 February 2012 15:09, Yury Selivanov <firstname.lastname@example.org>
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 = ()
ctxs += (ApplicationProfilerContext(),)
ctxs += (ApplicationLoggingContext(),)
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:
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?
Python-ideas mailing list