# Confusing error message when expressing an integer

**URL:** <https://discuss.python.org/t/confusing-error-message-when-expressing-an-integer/37937>\
**Category:** Core Development\
**Created:** [November 4, 2023, 7:43pm UTC](https://discuss.python.org/t/confusing-error-message-when-expressing-an-integer/37937 "2023-11-04T19:43:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Baofeng](https://avatars.discourse-cdn.com/v4/letter/b/dec6dc/32.png) [@Baofeng](https://discuss.python.org/u/Baofeng)\
**Post date:** [November 4, 2023, 7:43pm UTC](https://discuss.python.org/t/confusing-error-message-when-expressing-an-integer/37937/1 "2023-11-04T19:43:00Z")

</div>

From [eBNF notation of integer](https://docs.python.org/3/reference/lexical_analysis.html#integer-literals) in python reference:

` decinteger ::= nonzerodigit (["_"] digit)* | "0"+ (["_"] "0")*`

I pick up 2nd alternative “0”+ ([“\_”] “0”)\* to test positive and negative cases respectively:

```auto
>>> 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 `octdigit`!

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.

Please comment.

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

---

<div class="post-metadata">

**Author:** ![Jelle](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/jelle/32/1049_2.png) [@Jelle](https://discuss.python.org/u/Jelle)\
**Post date:** [November 4, 2023, 7:53pm UTC](https://discuss.python.org/t/confusing-error-message-when-expressing-an-integer/37937/2 "2023-11-04T19:53:55Z")

</div>

The reason for the message is that historically in Python 2, leading 0s indicated an octal integer:

```auto
Python 2.7.18 (default, Oct 5 2023, 10:23:23) 
[GCC Apple LLVM 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 010
8

```

However, now that Python 2 is mostly gone, the “use 0o prefix for octal integers” may cause more confusion than it prevents. Perhaps we should simply remove that part of the error.

---

<div class="post-metadata">

**Author:** ![Baofeng](https://avatars.discourse-cdn.com/v4/letter/b/dec6dc/32.png) [@Baofeng](https://discuss.python.org/u/Baofeng)\
**Post date:** [November 4, 2023, 8:10pm UTC](https://discuss.python.org/t/confusing-error-message-when-expressing-an-integer/37937/5 "2023-11-04T20:10:13Z")

</div>

> [@Jelle](#):
>
> Perhaps we should simply remove that part of the error.

Agree. And… to be more precise, better add below bolded content:  
leading zeros in a **non-zero** decimal integer literals are not permitted

---

<div class="post-metadata">

**Author:** ![Baofeng](https://avatars.discourse-cdn.com/v4/letter/b/dec6dc/32.png) [@Baofeng](https://discuss.python.org/u/Baofeng)\
**Post date:** [November 4, 2023, 8:22pm UTC](https://discuss.python.org/t/confusing-error-message-when-expressing-an-integer/37937/6 "2023-11-04T20:22:03Z")

</div>

Aha, I found it is also documented in PLR:

> Note that leading zeros in a non-zero decimal number are not allowed.
