
Thanks for taking the time to write this PEP, Chris, even though I'm -1 on the idea. I'm glad to just have this as a historical document for the idea. On Tue, 27 Feb 2018 at 22:53 Chris Angelico <rosuav@gmail.com> wrote:
On Wed, Feb 28, 2018 at 4:52 PM, Robert Vanden Eynde <robertve92@gmail.com> wrote:
Hello Chris and Rob,
did you compare your proposal tothe subject called "[Python-ideas] Temporary variables in comprehensions" on this month list ?
Yes, I did; that's one of many threads on the subject, and is part of why I'm writing this up.
One section that I have yet to write is "alternative syntax proposals", which is where I'd collect all of those together.
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)] ... 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.
This is exactly why I am writing up a PEP. Ultimately, it should list every viable proposal (or group of similar proposals), with the arguments for and against. Contributions of actual paragraphs of text are VERY welcome; simply pointing out "hey, don't forget this one" is also welcome, but I then have to go and write something up, so it'll take a bit longer :)
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".
And also the standard library's tkinter.dnd.Icon, according to a quick 'git grep'; but that might be just an example, rather than actually being covered by backward-compatibility guarantees. I think "given" is the strongest contender of the three, but I'm just mentioning all three together.
A new version of the PEP has been pushed, and should be live within a few minutes.
https://www.python.org/dev/peps/pep-0572/
Whatever I've missed, do please let me know. This document should end up incorporating, or at least mentioning, all of the proposals you cited.
ChrisA _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/