From eBNF notation of integer in python reference:
decinteger ::= nonzerodigit (["_"] digit)* | "0"+ (["_"] "0")*
I pick up 2nd alternative “0”+ ([“_”] “0”)* to test positive and negative cases respectively:
>>> c = 0_0_00000_0 >>> c = 0_0_00000_9 File "<stdin>", line 1 c = 0_0_00000_9 ^^^^^^^^^^ SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers
I do expect an error in 2nd statement, but how could it be presumed an octal integers?
Literally, if there is a leading zero to present a *non-zero integer, it could be any of bininteger, octinteger or hexinteger. This error message sounds a little odd as 9 is not even a valid
Hereby, I would suggest the error message to be more instructive like:
SyntaxError: leading zeros in a non-zero decimal integer literals are not permitted; use 0b, 0o, 0x for bininteger, octinteger or hexinteger integers, respectively.
P.S. test env:
Python 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 bit (
AMD64)] on win32