This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients serhiy.storchaka
Date 2020-01-05.11:33:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1578224025.61.0.7633610275.issue39219@roundup.psfhosted.org>
In-reply-to
Content
SyntaxError can be raised at different stages of compiling. In some places the source text is not available and should be read from the file using the file name. Which does not work in case of compiling a string or reading from stdin.

>>> 0z
  File "<stdin>", line 1
    0z
     ^
SyntaxError: invalid syntax
>>> 0xz
  File "<stdin>", line 1
SyntaxError: invalid hexadecimal literal

In the second example above the source line and the caret are absent in REPL.

The proposed PR fixes two errors in raising a SyntaxError in the tokenizer.

1. The text of the source line was not set if an exception was raised in the tokenizer. Since most of these exceptions (with more detailed description) were added in 3.8 I consider this a regressions.

2. The offset attribute was an offset in bytes. Now it is an offset in characters.

It only fixes errors in the tokenizer. There are similar bugs in other parts of the compiler.

This issue is based on the article https://aroberge.blogspot.com/2019/12/a-tiny-python-exception-oddity.html .
History
Date User Action Args
2020-01-05 11:33:45serhiy.storchakasetrecipients: + serhiy.storchaka
2020-01-05 11:33:45serhiy.storchakasetmessageid: <1578224025.61.0.7633610275.issue39219@roundup.psfhosted.org>
2020-01-05 11:33:45serhiy.storchakalinkissue39219 messages
2020-01-05 11:33:45serhiy.storchakacreate