[New-bugs-announce] [issue38277] Allowing conditions with assignment expressions in comprehensions without parantheses

Arne Recknagel report at bugs.python.org
Wed Sep 25 10:20:15 EDT 2019


New submission from Arne Recknagel <arne.recknagel at hotmail.com>:

All code is run on python build from the current 3.8 branch.

The following doesn't work:

  >>> [x for x in 'foo' if y := True]
    File "<stdin>", line 1
      [x for x in 'foo' if y := True]
                             ^
  SyntaxError: invalid syntax

While this does:

  >>> [x for x in 'foo' if (y := True)]
  ['f', 'o', 'o']

Since assignment expressions work without parentheses in normal if-clauses and there being no mention on it explicitly being disallowed, this seems to either be a bug or an oversight in the documentation (with my own opinion, for what it's worth, being that it's a bug).

----------
messages: 353203
nosy: arne, emilyemorehouse
priority: normal
severity: normal
status: open
title: Allowing conditions with assignment expressions in comprehensions without parantheses
versions: Python 3.8

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


More information about the New-bugs-announce mailing list