Re : Undelivered Mail Returned to Sender
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
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
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 Regards, pascal
Pascal Chambon wrote:
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
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
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
Yes I'm +1 for "with A() as a, B() as b, C() as c:", too. For the deleyedNested(...) thing I'm -1 however.
Mathias Panzenböck schrieb:
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
Yes I'm +1 for "with A() as a, B() as b, C() as c:", too. For the deleyedNested(...) thing I'm -1 however.
I'm also +1 (explicitly on this syntax variant, not "with A(),B() as a,b", since it seems a more logical step from the nested with statements). Mattias and I have a patch in working; I expect it will be fine to amend PEP 343 for this when it's ready. Georg
participants (3)
-
Georg Brandl
-
Mathias Panzenböck
-
Pascal Chambon