[New-bugs-announce] [issue44448] Suggestion: change existing error message for invalid function name

Andre Roberge report at bugs.python.org
Thu Jun 17 21:08:57 EDT 2021


New submission from Andre Roberge <andre.roberge at gmail.com>:

Consider the following two examples with the latest beta release:

Python 3.10.0b3 ...

>>> def 3job(x):
  File "<stdin>", line 1
    def 3job(x):
         ^
SyntaxError: invalid imaginary literal

>>> def 3ob(x):
  File "<stdin>", line 1
    def 3ob(x):
        ^
SyntaxError: invalid decimal literal

In most situations, these error messages are fantastic improvements compared with what was done previously. Here however, as they are intended to be used as function names, perhaps they could be improved.

**If** it is easy to check if those "invalid number literals" are preceded by "def" during the analysis, perhaps a better error message might be

SyntaxError: invalid function name

If such an analysis would be difficult to do, I would suggest to simply close this issue as these examples are probably almost never going to be seen in real-life situations.


(One might also consider to change the error message in the cases of "invalid octal" and "invalid hexadecimal" when they are used as function names.)

----------
components: Parser
messages: 396027
nosy: aroberge, lys.nikolaou, pablogsal
priority: normal
severity: normal
status: open
title: Suggestion: change existing error message for invalid function name
versions: Python 3.10

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


More information about the New-bugs-announce mailing list