[Python-ideas] Anaphoric if

Andrey Fedorov anfedorov at gmail.com
Sat Apr 24 02:39:52 CEST 2010


On Fri, Apr 23, 2010 at 7:18 PM, Chris Rebert <pyideas at rebertia.com> wrote:

> Master Yoda had me google "python-ideas if assignment", which was fruitful:
>
> [Python-ideas] Inline assignment expression:
> http://mail.python.org/pipermail/python-ideas/2009-March/003423.html
>
> Post in same thread summarizing rejection reasons:
> http://mail.python.org/pipermail/python-ideas/2009-March/003440.html
>

Thanks! But, I'm not really thinking about creating an inline assignment
expressions: those feel un-Pythonic the same way the ++ operator is.

I'm talking about anaphoric if: that is, extending the if_stmt to include
["as" target] after its expression. Actually, that seems to be what the
original bug filed was about [1], *not* anything to do with assignment
expressions or funky "backwards assignment" syntax who-knows-where.

On Mar 15, 2009, Nick Coghlan wrote:

> If you look at the current uses for 'as' it is never for direct assignment:


Right, it's used for a different kind of assignment each time. The
commonality is that it's used for the "appropriate" assignment for the
context, with the target appearing after "as".

On Fri, Apr 23, 2010 at 8:23 PM, Jess Austin <jess.austin at gmail.com> wrote:

> A question for the sake of completeness: would "if not foo() as x: ... x"
> mean "x = foo(); if not x: ... x"?
>

No, it would mean: "x = not foo(); if x: ...x". That is, it would be part of
the "if" statement, assigning the value of the expression after "if" to the
target after "as". It doesn't make sense to me to make exceptions for one
kind of expression over another.

On Fri, Apr 23, 2010 at 8:26 PM, Raymond Hettinger <
raymond.hettinger at gmail.com> wrote:

> FWIW, I'm +1 on the idea, especially if it can be also applied to
> while-loops.
>

Yup, using doing the same for while-loops makes even more sense.

It looks very readable
>

Agreed.


> We do have a language moratorium in effect, so your odds of success are
> slim.
>

Patiently counting down the days... :)

Cheers,
Andrey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20100423/ac6b4def/attachment.html>


More information about the Python-ideas mailing list