[New-bugs-announce] [issue45801] Incorrect "Perhaps you forgot a comma" hint

Andre Roberge report at bugs.python.org
Sat Nov 13 12:00:06 EST 2021


New submission from Andre Roberge <andre.roberge at gmail.com>:

Python 3.10 and 3.11:

>>> sum[i for i in [1, 2, 3] if i%2==0]
  File "<stdin>", line 1
    sum[i for i in [1, 2, 3] if i%2==0]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?

Furthermore, I don't find that highlighting the entire statement (or parts of it, if we use print(sum[...]) is very useful in attempting to find the source of the error.

In previous versions, we would get the following:

>>> sum[i for i in [1, 2, 3] if i%2==0]
  File "<stdin>", line 1
    sum[i for i in [1, 2, 3] if i%2==0]
          ^
SyntaxError: invalid syntax

----------
components: Parser
messages: 406287
nosy: aroberge, lys.nikolaou, pablogsal
priority: normal
severity: normal
status: open
title: Incorrect "Perhaps you forgot a comma" hint
versions: Python 3.10, Python 3.11

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


More information about the New-bugs-announce mailing list