You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2021-05-19.18:13:27.800>created_at=<Date2021-05-18.09:49:58.120>labels= ['interpreter-core', '3.9']
title='Wrong syntax error hint when spurious colon present in function keyword comprehension assignment'updated_at=<Date2021-05-19.18:28:35.119>user='https://github.com/gerritholl'
In Python 3.9.4, in a function call, when assigning a comprehension to a keyword argument, and the comprehension contains a spurious colon (if a list or set comprehension) or a missing value (when a dict comprehension), the syntax error message gives a hint that incorrectly suggests that the expression cannot contain an assignment:
$ python
Python 3.9.4 | packaged by conda-forge | (default, May 10 2021, 22:13:33)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> f(a={x: for x in {}})
File "<stdin>", line 1
f(a={x: for x in {}})
^
SyntaxError: expression cannot contain assignment, perhaps you meant "=="?
I certainly didn't mean "==" here. The syntax is correct if I either remove the :, or add a value after the :, such as:
>> f(a={x:x for x in {}})
>> f(a={x for x in {}})
(correct syntax, succeeds if f is defined).
The problem here has nothing to do with assignments being in the wrong place, so the message reported by cpython is incorrect.
In Python 3.8.10 Python simply and correctly states that the syntax is incorrect:
>>> f(a={x: for x in {}})
File "<stdin>", line 1
f(a={x: for x in {}})
^
SyntaxError: invalid syntax
New changeset d4a9264 by Pablo Galindo in branch '3.9':
[3.9] bpo-44168: Fix error message in the parser for keyword arguments for invalid expressions (GH-26210) (GH-26250) d4a9264
New changeset ec0699c by Miss Islington (bot) in branch '3.10': bpo-44168: Fix error message in the parser for keyword arguments for invalid expressions (GH-26210) (GH-26247) ec0699c
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: