New submission from Andre Roberge <andre.robe...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue44180>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to