Missing commas while writing lists is a pretty common source of errors (for me at least). In Python 3.8 and lower, missing a comma in a list passed to a function as a keyword argument generates a sensible error that clearly points out the error's location.
Python 3.8.5 (default, Sep 4 2020, 07:30:14)
[GCC 7.3.0] :: Anaconda, Inc. on linux
>>> def myfunc(**kwargs):
... pass
...
>>> myfunc(mylist=[10, 10, 45 45])
File "<stdin>", line 1
myfunc(mylist=[10, 10, 45 45])
^
SyntaxError: invalid syntax
In Python 3.9, the same code gives a different error message (with the same error type), which is much harder to understand and took me in a completely different direction while debugging.
Python 3.9.2 (default, Mar 3 2021, 20:02:32)
[GCC 7.3.0] :: Anaconda, Inc. on Linux
>>> def myfunc(**kwargs):
... pass
...
>>> myfunc(mylist=[10, 10, 45 45])
File "<stdin>", line 1
myfunc(mylist=[10, 10, 45 45])
^
SyntaxError: expression cannot contain assignment, perhaps you meant "=="?
Assigning a list to a variable seems to handled "correctly" though.
>>> mylist = [10, 10, 45 45]
File "<stdin>", line 1
mylist = [10, 10, 45 45]
^
SyntaxError: invalid syntax
This is definitely related to the new PEG parser, as starting python with python -X oldparser
gives the previous behaviour back.
I would like to know how is this error handled differently in these parsers? Why does the error message given by the PEG parser seem to be so off here? What does the PEG parser think is happening here? Is there a class of errors that will be handled differently in the PEG parser?