[New-bugs-announce] [issue44180] SyntaxError misidentified in 3.10.0b1 when = used instead of : in dict literal
Andre Roberge
report at bugs.python.org
Wed May 19 14:38:05 EDT 2021
New submission from Andre Roberge <andre.roberge at gmail.com>:
When an equal sign is used instead of a colon in creating a dict literal, depending on the context, either the "bad token" is misidentified OR the would-be helpful error message is incorrect in this particular case.
1) Example of bad token.
Previously, the = sign was identified correctly:
>>> ages = {'Alice'=22, 'Bob'=23}
File "<stdin>", line 1
ages = {'Alice'=22, 'Bob'=23}
^
SyntaxError: invalid syntax
With Python 3.10.0b1, the comma is identified as the bad token:
>>> ages = {'Alice'=22, 'Bob'=23}
File "<stdin>", line 1
ages = {'Alice'=22, 'Bob'=23}
^
SyntaxError: invalid syntax
2) Example of incorrect error message
Previously, we got the traditional and unhelpful "invalid syntax" but with the bad token identified correctly:
>>> ages = {'Alice'=22}
File "<stdin>", line 1
ages = {'Alice'=22}
^
SyntaxError: invalid syntax
With Python 3.10.0b1, we get the following:
>>> ages = {'Alice'=22}
File "<stdin>", line 1
ages = {'Alice'=22}
^^^^^^^
SyntaxError: cannot assign to literal here. Maybe you meant '==' instead of '='?
I suspect that the ratio (== suggestion correct/ : suggestion correct) would be vanishingly small. ;-)
----------
components: Parser
messages: 393964
nosy: aroberge, lys.nikolaou, pablogsal
priority: normal
severity: normal
status: open
title: SyntaxError misidentified in 3.10.0b1 when = used instead of : in dict literal
versions: Python 3.10
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44180>
_______________________________________
More information about the New-bugs-announce
mailing list