
April 28, 2009
10:09 p.m.
Pascal Chambon wrote:
I agree with the idea of auto-nesting "with", however in the case you pointed out, the main problem was the early evaluation of context managers ; maybe a solution would be to delay the creation of context managers, with something like a partial application (cf functools).
Roughly, we'd need a "delayedNested" function, which takes zero-argument callables as parameters, and calls/instanciates them inside itself.
Then just call* delayedNested(partial(A,...arguments...), partial(B, ...arguments...))*/ /to have what you want.
It would be much shorter and more readable to manually nest the with statements. -panzi