[New-bugs-announce] [issue45716] Confusing parsing error message when trying to use True as keyword argument

Carl Friedrich Bolz-Tereick report at bugs.python.org
Thu Nov 4 13:45:48 EDT 2021


New submission from Carl Friedrich Bolz-Tereick <cfbolz at gmx.de>:

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?

----------
messages: 405741
nosy: Carl.Friedrich.Bolz
priority: normal
severity: normal
status: open
title: Confusing parsing error message when trying to use True as keyword argument

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45716>
_______________________________________


More information about the New-bugs-announce mailing list