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.
|