[Python-Dev] multi-with statement (original) (raw)

Fredrik Johansson fredrik.johansson at gmail.com
Sat May 2 21:26:14 CEST 2009


On Sat, May 2, 2009 at 9:01 PM, Georg Brandl <g.brandl at gmx.net> wrote:

Hi,

this is just a short notice that Mattias Brändström and I have finished a patch to implement the previously discussed and mostly warmly welcomed extension to with's syntax, allowing with A() as a, B() as b: to be written instead of with A() as a: with B() as b: This syntax was chosen (over "with A(), B() as a, b:") because it has more syntactical similarity to the written-out version.  Also, our current uses of "as" all have only one expression on the right. The patch implements it as a simple AST transformation, which guarantees semantic equivalence.  It is at <http://codereview.appspot.com/53094>. If there is no strong opposition, I will commit it and port it to py3k before 3.1 enters beta stage. cheers, Georg

I was hoping for the other syntax in order to be able to create a nested context in advance as a simple tuple:

with A, B: pass

context = A, B with context: pass

(I.e. a tuple, or perhaps any iterable, would be a valid context manager.)

With the syntax in the patch, I will still have to implement a custom nesting context manager to do this, which sort of defeats the purpose.

Fredrik



More information about the Python-Dev mailing list