[Python-ideas] with statement: multiple context manager

Mathias Panzenböck grosser.meister.morti at gmx.net
Thu Mar 26 16:07:25 CET 2009


Sturla Molden wrote:
 > On 3/1/2009 9:57 PM, Christian Heimes wrote:
 >
 >>   with a, b as x, d as y:
 >
 > I'd like to add that parentheses improve readability here:
 >
 >    with a, (b as x), (d as y):
 >
 > I am worried the proposed syntax could be a source of confusion and
 > errors. E.g. when looking at
 >
 >    with a,b as c,d:
 >
 > my eyes read
 >
 >    with nested(a,b) as c,d:
 >
 > when Python would read
 >
 >    with a,(b as c),d:
 >
 >

Good point. Maybe that would be better:

    with a,b as c,d:

reads as:

    with nested(a,b) as c,d:

This means there can only be one "as" in a with statement with the further 
implication that even unneeded values have to be assigned:

    with a,b,c as x,unused,y:

Not as nice, but much more unambiguous. Unambiguity is what we need, I think. 
You can always assing to _, wich is very commonly used for unneeded values 
(well, or for the l10n hook - so using that name would not be very unambiguous).

	-panzi



More information about the Python-ideas mailing list