Title: Suggestion: change existing error message for invalid function name
Type: Stage: resolved
Components: Parser Versions: Python 3.10
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: aroberge, lys.nikolaou, pablogsal
Priority: normal Keywords:

Created on 2021-06-18 01:08 by aroberge, last changed 2021-06-18 11:03 by pablogsal. This issue is now closed.

Messages (3)
msg396027 - (view) Author: Andre Roberge (aroberge) * Date: 2021-06-18 01:08
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.)
msg396045 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-06-18 11:02
Unfortunately these are tokenizer errors and the tokenizer had no idea of what's a function, so introducing syntactic structure in the error is going to be quite error prone, as the tokenizer still sees whitespace and other stuff that the parser doesn't.
msg396046 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-06-18 11:03
But thanks a lot for the proposal!
Date User Action Args
2021-06-18 11:03:00pablogsalsetmessages: + msg396046
2021-06-18 11:02:51pablogsalsetstatus: open -> closed
resolution: rejected
messages: + msg396045

stage: resolved
2021-06-18 01:08:57arobergecreate