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.

classification
Title: SyntaxError in Python 3.10.0b1: wrong token for missing comma
Type: behavior Stage:
Components: Parser Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: aroberge, lys.nikolaou, pablogsal
Priority: normal Keywords:

Created on 2021-05-19 21:22 by aroberge, last changed 2022-04-11 14:59 by admin.

Messages (1)
msg393976 - (view) Author: Andre Roberge (aroberge) * Date: 2021-05-19 21:22
When forgetting a comma in writing a dict literal spanning multiple lines,
the "bad token" is wrongly idenfied with Python 3.10.0b1.

>>> a = {'a': 1
...      'b': 2
  File "<stdin>", line 1
    a = {'a': 1
              ^
SyntaxError: invalid syntax. Perhaps you forgot a comma?


Previously, this was shown:

>>> a = {'a': 1
...      'b': 2
  File "<stdin>", line 2
    'b': 2
    ^
SyntaxError: invalid syntax

However, I hasten to add that the new hint about a missing comma is spot on,
and likely to be extremely useful.

Note: this is based on my "intuition" built from previous version where the token identified by ^
was the first token that the Python parser was not able to make sense of.
Now that the parser highlight a range (if relevant tokens are on a single line),
it makes sense to include tokens preceding the "bad token".
However, when we have an error where such range
spans multiple lines, it can create "problems" such as that shown above.

Perhaps this is not worth attempting to fix and Python programmers like me will have to develop a "new intuition" in such cases (and "fix" friendly so that it can figure out the correct "bad token"
independently of cPython's information)
... and this bug report can be simply closed.
History
Date User Action Args
2022-04-11 14:59:45adminsetgithub: 88347
2021-05-19 21:22:04arobergecreate