[Python-Dev] Acquire/release functionality (Was: Extended Function syntax)

Moore, Paul Paul.Moore@atosorigin.com
Mon, 3 Feb 2003 12:54:06 -0000


From: Bernhard Herzog [mailto:bh@intevation.de]
> IMO if you want multiple controllers for a with statement you
> should just nest the withs:
>
> with var1 =3D expr1:
>     with var2 =3D expr2:
>         suite

To some extent, an important point of the with expression is to
simplify the overall control construct, and to reduce the level
of nesting needed. Combining the variables was intended to help
with this.

> This makes the order in which the methods of the varN will be
> called obvious.

It should be fairly obvious from the combined form too - enter in
the order specified, and leave in reverse order.

> > In this, any varN can be omitted and a dummy hidden variable
> > is used.=20
>=20
> Meaning something like
>=20
> with var1, , var3 =3D expr1, expr2, expr3:
>     suite
>=20
> I guess. Urgs.

Agreed. I didn't mean that. Originally, I'd specified this as

    with var1 =3D expr1, var2 =3D expr2, ...:

but I switched to parallel the normal multiple assignment idiom.

How about

    with [ var1, var2, ... =3D ] expr1, expr2, ...

so that you can omit all or none? That's basically just like a
normal tuple assignment.

> Nested withs handle this in a cleaner way as well, IMO.

Yes, I guess they do. I'll make sure I have this as at least an
option in the PEP. I still like the combined form, just because
it reduces the tendency to drift towards the right margin. But
I'm not convinced it will be important particularly often...

Thanks for the comments,
Paul.