-
-
Notifications
You must be signed in to change notification settings - Fork 29.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion for better syntax errors in tokenizer errors #88483
Comments
Python 3.10.0b2 (tags/v3.10.0b2:3173141, Jun 1 2021, 09:05:29) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 0777
File "<stdin>", line 1
0777
^
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers
>>> 000123
File "<stdin>", line 1
000123
^
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers The ^ is placed below the last digit. >>> 0777
File "<stdin>", line 1
0777
^
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers
>>> 000123
File "<stdin>", line 1
000123
^^^
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers Opinions? |
Another 2 problems:
1.
>>> 0b1112
File "<stdin>", line 1
0b1112
^
SyntaxError: invalid digit '2' in binary literal
>>> 0o5780
File "<stdin>", line 1
0o5780
^
SyntaxError: invalid digit '8' in octal literal
But:
>>> 0x2fag
File "<stdin>", line 1
0x2fag
^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
>>>
Is this expected?
2.
>>> 0o91
File "<stdin>", line 1
0o91
^
SyntaxError: invalid digit '9' in octal literal
>>> 0b21
File "<stdin>", line 1
0b21
^
SyntaxError: invalid digit '2' in binary literal The ^ is misplaced again, even though, say the 0b1112 example above works. |
Yes, is an edge case of python identifiying two tokens together except that there is no space: >>> 3 4
File "<stdin>", line 1
3 4
^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma? I honestly don't share your concerns that these things are "misleading". The caret is pointing to the token that is incorrect 0777. The tokenizer errors always point at the end of the token (we still have not implemented ranged errors for the tokenizer). This is true in all the cases you present. |
PR 26555 does some improvements to your examples: >>> 0777
File "<stdin>", line 1
0777
^
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers
>>> 000007777
File "<stdin>", line 1
000007777
^^^^^
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers
>>> 0b1112
File "<stdin>", line 1
0b1112
^
SyntaxError: invalid digit '2' in binary literal
>>> 0o91
File "<stdin>", line 1
0o91
^
SyntaxError: invalid digit '9' in octal literal
>>> 0b21
File "<stdin>", line 1
0b21
^
SyntaxError: invalid digit '2' in binary literal
>>> |
See also bpo-43833. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: