[Python-ideas] PEP 572: Statement-Local Name Bindings

Robert Vanden Eynde robertve92 at gmail.com
Wed Feb 28 00:52:41 EST 2018


Hello Chris and Rob,

did you compare your proposal tothe subject called "[Python-ideas]
Temporary variables in comprehensions" on this month list ?

If you don't want to go through all the mails, I tried to summarize the
ideas in this mail : https://mail.python.org/pipermail/python-ideas/2018-
February/048987.html

In a nutshell one of the proposed syntax was

stuff = [(y, y) where y = f(x) for x in range(5)]

Or with your choice of keyword,

stuff = [(y, y) with y = f(x) for x in range(5)]

Your proposal uses the *reverse* syntax :

stuff = [(y, y) with f(x) as y for x in range (5)]

Your syntax was already proposed in 2008 and you can see in the response to
my mail (https://mail.python.org/pipermail/python-ideas/2018-
February/049000.html)

The first example with the "where y = f(x)" can already be compiled on a
CPython branch called "where-expr" on https://github.com/
thektulu/cpython/commit/9e669d63d292a639eb6ba2ecea3ed2c0c23f2636

You can see all the conversation on subject "Tempory variables in
comprehensions" on https://mail.python.org/pipermail/python-ideas/2018-
February/thread.html#start

I wish I could write a pep to summarize all the discussions (including
yours, my summary, including real world examples, including pro's and
con's), or should I do a gist on GitHub so that we can talk in a more
"forum like" manner where people can edit their answers and modify the
document ? This mailing is driving me a bit crazy.

As Rob pointed out, your syntax "(f(x) as y, y)" is really assymmetric and
"(y, y) with f(x) as y" or "(y, y) with y = f(x)" is probably prefered.
Moreover I agree with you the choice of "with" keyword could be confused
with the "with f(x) as x:" statement in context management, so maybe "with
x = f(x)" would cleary makes it different ? Or using a new keyword like
"where y = f(x)", "let y = f(x)" or probably better "given y = f(x)",
"given" isn't used in current librairies like numpy.where or sql alchemy
"where".

In the conversation, a lot of people wanted real world examples where it's
obvious the new syntax is better.
Cheers,

Robert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180228/c89ffd6e/attachment.html>


More information about the Python-ideas mailing list