[Python-ideas] Re : Undelivered Mail Returned to Sender

Pascal Chambon chambon.pascal at wanadoo.fr
Tue Apr 28 22:45:56 CEST 2009

 >Mathias Panzenböck a écrit :
 >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 
 >> 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 
 >  -panzi

Indeed, but the constructions we talk about would allow nesting dozens 
of context managers without any problem ;
Well then, you'll ask me "what kind of a perverse would need to 
imbricate dozens of context managers ???" ; sincerely I don't know ^^

But since "flat is better than nested", even just for 2 or 3 context 
managers, I feel a construct like "with A() as a, B() as b, C() as c:" 
is anyway better than 3 nested with statements


More information about the Python-ideas mailing list