This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Confusing parsing error message when trying to use True as keyword argument
Type: Stage: resolved
Components: Parser Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Carl.Friedrich.Bolz, aroberge, lys.nikolaou, pablogsal
Priority: normal Keywords: patch

Created on 2021-11-04 17:45 by Carl.Friedrich.Bolz, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 29413 merged pablogsal, 2021-11-04 20:19
PR 29428 merged pablogsal, 2021-11-05 13:59
Messages (3)
msg405741 - (view) Author: Carl Friedrich Bolz-Tereick (Carl.Friedrich.Bolz) * Date: 2021-11-04 17:45
A bit of a nitpick, but the following SyntaxError message is a bit confusing:

>>> f(True=1)
  File "<stdin>", line 1
    f(True=1)
      ^^^^^
SyntaxError: expression cannot contain assignment, perhaps you meant "=="?

The problem with that line is not that it contains an assignment, it's almost a valid keyword argument after all. The problem is that the name of the keyword is True, which is no longer a name you can assign to. It would be better to produce the same error as with __debug__:

>>> f(__debug__=1)
  File "<stdin>", line 1
SyntaxError: cannot assign to __debug__

The latter error message is however produced by the compiler, not the parser I think?
msg405798 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-11-05 13:55
New changeset e2d65630f36712dbdbf7711520c985c526a5cc25 by Pablo Galindo Salgado in branch 'main':
bpo-45716: Improve the error message when using True/False/None as keywords in a call (GH-29413)
https://github.com/python/cpython/commit/e2d65630f36712dbdbf7711520c985c526a5cc25
msg406439 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-11-16 22:31
New changeset 5618c81e139419b4665dc1f1e8a468738546f542 by Pablo Galindo Salgado in branch '3.10':
[3.10] bpo-45716: Improve the error message when using True/False/None as keywords in a call (GH-29413). (GH-29428)
https://github.com/python/cpython/commit/5618c81e139419b4665dc1f1e8a468738546f542
History
Date User Action Args
2022-04-11 14:59:52adminsetgithub: 89879
2021-11-16 22:31:49pablogsalsetmessages: + msg406439
2021-11-05 13:59:51pablogsalsetpull_requests: + pull_request27683
2021-11-05 13:57:15pablogsalsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-11-05 13:55:10pablogsalsetmessages: + msg405798
2021-11-04 20:19:58pablogsalsetkeywords: + patch
stage: patch review
pull_requests: + pull_request27665
2021-11-04 18:48:53arobergesetnosy: + aroberge
2021-11-04 18:40:02eric.smithsetnosy: + pablogsal, lys.nikolaou
components: + Parser
2021-11-04 17:45:48Carl.Friedrich.Bolzcreate