classification
Title: Confusing "invalid token" exception when integers have leading zero
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.5
process
Status: closed Resolution: duplicate
Dependencies: Superseder: 'SyntaxError: invalid token' is unfriendly
View: 20608
Assigned To: docs@python Nosy List: John Parejko, berker.peksag
Priority: normal Keywords:

Created on 2017-01-03 21:12 by John Parejko, last changed 2017-01-03 23:21 by berker.peksag. This issue is now closed.

Messages (3)
msg284591 - (view) Author: John Parejko (John Parejko) Date: 2017-01-03 21:12
As described in PEP-3127, the "leading-zeros" formatting for octal was removed from python 3. This is a good thing(tm), but the recommendation of that PEP to improve the error message of the raised exception[1] was apparently never implemented. I just ran into this while with some recently-ported python2 code, and it took a while to figure out the problem.

Although this is going to be less of a problem with time as people convert to pure python3, it will be very helpful during the transition period.

>>> 0o007
7
>>> 007
  File "<stdin>", line 1
    007
      ^
SyntaxError: invalid token


1: https://www.python.org/dev/peps/pep-3127/#id17
msg284592 - (view) Author: John Parejko (John Parejko) Date: 2017-01-03 21:31
Ah, I finally found a related issue, and it looks like it has patches! https://bugs.python.org/issue20608

If someone could check that over and merge it, that would be wonderful!
msg284602 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2017-01-03 23:21
Thanks for finding the duplicate. I'm closing this as a duplicate of issue 20608.
History
Date User Action Args
2017-01-03 23:21:42berker.peksagsetstatus: open -> closed

superseder: 'SyntaxError: invalid token' is unfriendly
components: - Documentation, 2to3 (2.x to 3.x conversion tool)
nosy: + berker.peksag, - docs@python
messages: + msg284602
resolution: duplicate
stage: resolved
2017-01-03 21:31:04John Parejkosetmessages: + msg284592
2017-01-03 21:12:51John Parejkocreate