[Python-Dev] "as" mania

Guido van Rossum guido at python.org
Tue Mar 7 19:00:18 CET 2006


On 3/7/06, Georg Brandl <g.brandl at gmx.net> wrote:
> > Have you even tried to define precise semantics for any of those, like
> > the expansion of "with E as V: B" in PEP 343?
>
> Easily.
>
> if expr as name:
>     BLOCK
>
> would be equivalent to
>
> name = expr
> if name:
>     BLOCK
> del name

You need to be a little more formal. What happens when there are elif
or else clauses? Why the del at all? (with doesn't delete VAR).

You also need to present a better motivation. What would be the point
of having a separate name for the value True or False when you already
know its value based on which branch you execute? And what exactly is
the big savings? If you look at the motivation for with E as V, V is
*not* assigned the value of E (but rather E.__context__().__enter__())
and the with statement as a whole has a very good reason for its
existence. Your proposal here lacks that.

> Same for while.

You aren't really trying, are you?  What would the point be of

NAME = EXPR
while NAME:
    BLOCK
del NAME

(Hint: while needs EXPR to be reevaluated each time through the loop.)

--
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list