[New-bugs-announce] [issue43755] lambda expression no longer valid at comp_if in Python 3.9

Saiyang Gou report at bugs.python.org
Tue Apr 6 16:07:25 EDT 2021


New submission from Saiyang Gou <gousaiyang223 at gmail.com>:

According to the documentation, a lambda expression at the `comp_if` position of a comprehension is allowed (can be parsed as `lambda_expr_nocond`). But this seems broken in Python 3.9 PEG parser. Example:

user at host:/$ python3.8
Python 3.8.9 (default, Apr  3 2021, 01:00:00)
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> [x for x in range(10) if lambda: 1]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>>
user at host:/$ python3.9
Python 3.9.3 (default, Apr  3 2021, 00:51:37)
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> [x for x in range(10) if lambda: 1]
  File "<stdin>", line 1
    [x for x in range(10) if lambda: 1]
                             ^
SyntaxError: invalid syntax

----------
messages: 390369
nosy: gousaiyang
priority: normal
severity: normal
status: open
title: lambda expression no longer valid at comp_if in Python 3.9
type: behavior
versions: Python 3.10, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43755>
_______________________________________


More information about the New-bugs-announce mailing list