Message393865
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
I have not tried Python 3.10b1. |
|
Date |
User |
Action |
Args |
2021-05-18 09:49:58 | Gerrit.Holl | set | recipients:
+ Gerrit.Holl, lys.nikolaou, pablogsal |
2021-05-18 09:49:58 | Gerrit.Holl | set | messageid: <1621331398.13.0.330386764302.issue44168@roundup.psfhosted.org> |
2021-05-18 09:49:58 | Gerrit.Holl | link | issue44168 messages |
2021-05-18 09:49:57 | Gerrit.Holl | create | |
|