This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: PEG parser doesn't allow lambda in for_if_clause
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.10, Python 3.9
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: BTaskaya, benjamin.peterson, gvanrossum, lys.nikolaou, pablogsal, serhiy.storchaka, slebedev, terry.reedy
Priority: normal Keywords: patch

Created on 2020-09-23 23:33 by slebedev, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 22394 closed BTaskaya, 2020-09-24 06:51
Messages (5)
msg377435 - (view) Author: Sergei Lebedev (slebedev) Date: 2020-09-23 23:33

[x for x in [] if lambda: x]

This parses fine in 3.8, but doesn't parse in 3.9 because the grammar expects a disjunction after if in for_if_clause [*]. While this change has zero practical significance, I think it might be useful to maintain a list of such changes for tooling authors (who might need to support multiple Python versions).

msg377511 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-09-25 23:20
After adding parens,
>>> [x for x in [] if (lambda: x)]
msg377514 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2020-09-26 00:27
I propose not to fix this, since it is pointless (a lambda is always truthy).

We can call it out in What's New in 3.9 -- as a very small footnote. :-)
msg377545 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2020-09-26 21:49
I concur with Guido: it makes the grammar slightly more complex for no gain. Also, the originally allowed rule does not allow *any* lambda but only the ones that are simple, which is a special case that makes it even more complex. In any case you can use parentheses to break this limitation.

Like Guido, I propose to add a very small comment to What's New in 3.9
msg377546 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2020-09-26 23:36
Okay, let's close this.
Date User Action Args
2022-04-11 14:59:35adminsetgithub: 86014
2020-09-26 23:36:40gvanrossumsetstatus: open -> closed
resolution: wont fix
messages: + msg377546

stage: patch review -> resolved
2020-09-26 21:49:42pablogsalsetmessages: + msg377545
2020-09-26 00:27:58gvanrossumsetmessages: + msg377514
2020-09-25 23:20:56terry.reedysetnosy: + terry.reedy
messages: + msg377511
2020-09-24 06:51:50BTaskayasetkeywords: + patch
nosy: + BTaskaya

pull_requests: + pull_request21434
stage: patch review
2020-09-24 06:46:26serhiy.storchakasetnosy: + gvanrossum, benjamin.peterson, serhiy.storchaka, pablogsal
2020-09-23 23:33:02slebedevcreate