[Python-ideas] If branch merging

random832 at fastmail.us random832 at fastmail.us
Sun Jun 7 17:04:03 CEST 2015

On Sun, Jun 7, 2015, at 08:20, Chris Angelico wrote:
> with expr as name:
> except expr as name:
> if expr as name:
> Three parallel ways to do something and capture it. It makes
> reasonable sense

The problem is, "with" and "except" create a variable whose scope is
limited to the enclosed block. The proposed "if... as..." does not, so
it's misleading.

If we don't like spelling it as = then invent a new operator, maybe :=
or something. Maybe even as.

My wider point, though, was that there's no argument for the
_functionality_ of allowing an assignment of the boolean condition of an
if statement that can't be generalized to allowing inline assignment of
anything (why not e.g. "if (expr as foo) > 5"? That, unlike the boolean,
might even be something that would be useful within the enclosed block.)

More information about the Python-ideas mailing list