gh-156894: Fix the position of syntax errors which cover a range - #156901
Conversation
The callers of _PyTokenizer_syntaxerror_known_range() pass columns in bytes, but SyntaxError.offset and end_offset are columns in characters. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
| # for the errors which cover a range | ||
| for source, offset, end_offset in [ | ||
| ('abcd = 00010', 8, 11), | ||
| ('\u03b1\u03b2\u03b3\u03b4 = 00010', 8, 11), |
There was a problem hiding this comment.
include a test with a unicode combining character (e.g. \u0301) which has zero display width
| ('\u03b1\u03b2\u03b3\u03b4 = 00010', 8, 11), | |
| ('\u03b1\u03b2\u03b3\u03b4 = 00010', 8, 11), | |
| ('e\u0301'*4 = 00010', 8, 11), |
There was a problem hiding this comment.
It counts code points, not visible width.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15. |
|
Sorry, @serhiy-storchaka, I could not cleanly backport this to |
|
Sorry, @serhiy-storchaka, I could not cleanly backport this to |
|
Sorry, @serhiy-storchaka, I could not cleanly backport this to |
|
GH-156926 is a backport of this pull request to the 3.15 branch. |
|
GH-156927 is a backport of this pull request to the 3.14 branch. |
|
GH-156928 is a backport of this pull request to the 3.13 branch. |
SyntaxError.offsetandend_offsetare columns in characters, but all callers of_PyTokenizer_syntaxerror_known_range()pass columns in bytes, so the reported position drifts by one column per preceding non-ASCII character:The conversion is done in
_syntaxerror_range(), so all three call sites are fixed at once, and the-1case is unaffected: it already counts characters.test_tokenize.test_tolerant_incompatible_prefix_position_after_non_asciiasserted the column in bytes, so its expected value changes from 6 to 5.