[Python-ideas] "While" suggestion

Greg Ewing greg.ewing at canterbury.ac.nz
Sat Jul 5 03:30:14 CEST 2008

Guido van Rossum wrote:

> If we were to add "while x as y:" in 3.1, I'm sure we'd get pressure
> to add "if x as y:" in 3.2, and then "if (x as y) and (p as q):" in
> 3.3, and so on.

All that could be short-circuited by making 'expr as name' a
valid expression in general from the outset.

However, that would make 'with x as y' inconsistent, because
it doesn't bind the value of x to y, but rather the result of
x.__enter__(). (Often it's the same thing, but it doesn't have
to be.)

Then there's the new form of except clause that uses 'as'
in another slightly different way.

So while this proposal might at first appear to make things
more consistent, it actually doesn't. The way things are, each
use of 'as' is unique, so it can be regarded as consistently
inconsistent. Introducing a general 'expr as name' construct
would set up an expectation that 'as' is simply a binding
operator, and then the existing uses would stick out more by
being inconsistently inconsistent. :-)


More information about the Python-ideas mailing list