New submission from Gerrit Holl <gerrit.h...@gmail.com>:
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. ---------- components: Parser messages: 393865 nosy: Gerrit.Holl, lys.nikolaou, pablogsal priority: normal severity: normal status: open title: Wrong syntax error hint when spurious colon present in function keyword comprehension assignment versions: Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue44168> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com