[issue44180] SyntaxError misidentified in 3.10.0b1 when = used instead of : in dict literal
Andre Roberge
report at bugs.python.org
Wed May 19 15:46:23 EDT 2021
Andre Roberge <andre.roberge at gmail.com> added the comment:
In the second case, I understand very well that it could have been a set literal. In my (limited) experience, I have never seen a set literal containing a single element obtained from an == comparison.
Since dict can be built by using keyword arguments, I tend to assume that using = in an literal that starts with { is meant to be a dict.
In
>>> ages = {'Alice' = 22}
replacing the equal sign by either ==, :, or a comma would generate no SyntaxError. Clearly (in my mind anyway, and in previous Python versions), the "bad token" is the equal sign, and not the string Alice.
Here's what I show with friendly:
======
>>> ages = {'Alice'=22}
Traceback (most recent call last):
File "<friendly-console:1>", line 1
ages = {'Alice'=22}
^
SyntaxError: invalid syntax
>>> why()
It is possible that you used an equal sign = instead of a colon : to assign values to keys in a dict before or at the
position indicated by ^.
=====
Admitedly, this suggestion could also be wrong - but the focus on this case (imo) should be on the "bad token" shown, which should be the equal sign.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44180>
_______________________________________
More information about the Python-bugs-list
mailing list