Title: Wrong error position for tokenizer errors reporting a range if the line contains non-ASCII characters · Issue #156894 · python/cpython · GitHub
Open Graph Title: Wrong error position for tokenizer errors reporting a range if the line contains non-ASCII characters · Issue #156894 · python/cpython
X Title: Wrong error position for tokenizer errors reporting a range if the line contains non-ASCII characters · Issue #156894 · python/cpython
Description: The tokenizer errors which report a range point at the wrong characters if the line contains non-ASCII characters before the error. >>> compile("aaaa = 00010", "
Open Graph Description: The tokenizer errors which report a range point at the wrong characters if the line contains non-ASCII characters before the error. >>> compile("aaaa = 00010", "
X Description: The tokenizer errors which report a range point at the wrong characters if the line contains non-ASCII characters before the error. >>> compile("aaaa = 00010", "<t>&qu...
Opengraph URL: https://github.com/python/cpython/issues/156894
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Wrong error position for tokenizer errors reporting a range if the line contains non-ASCII characters","articleBody":"The tokenizer errors which report a range point at the wrong characters if the line contains non-ASCII characters before the error.\n\n```pycon\n>>> compile(\"aaaa = 00010\", \"\u003ct>\", \"exec\")\n File \"\u003ct>\", line 1\n aaaa = 00010\n ^^^\nSyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers\n>>> compile(\"фффф = 00010\", \"\u003ct>\", \"exec\")\n File \"\u003ct>\", line 1\n фффф = 00010\n ^\nSyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers\n```\n\nBoth lines should mark `000`; the second one is shifted right by one column per preceding non-ASCII character (`offset=8, end_offset=11` versus `offset=12, end_offset=15`).\n\nThe same happens with incompatible string prefixes:\n\n```pycon\n>>> compile(\"фф = ub'a'\", \"\u003ct>\", \"exec\")\n File \"\u003ct>\", line 1\n фф = ub'a'\n ^^\nSyntaxError: 'u' and 'b' prefixes are incompatible\n```\n\n`SyntaxError.offset` and `end_offset` are character columns, but every caller of `_PyTokenizer_syntaxerror_known_range()` passes byte offsets:\n\n* `Parser/lexer/number.c:238` — `tok->start + 1 - tok->line_start`, `zeros_end - tok->line_start`\n* `Parser/lexer/string.c:187` — the same expressions\n* `Parser/tokenizer/decoder.c:252` — `0`, `end_col` (only for a BOM-with-cookie line, so ASCII in practice)\n\n`_PyTokenizer_syntaxerror()` (the `-1, -1` case) is not affected: it computes the column by decoding the line prefix with `PyUnicode_DecodeUTF8(..., \"replace\")`.\n\nThe same class of bug was fixed for other errors in gh-102310 and gh-102312; these call sites were missed.\n\nThe fix could be either to convert in `_syntaxerror_range()` with `_PyPegen_byte_offset_to_character_offset_raw()`, which fixes all callers at once, or to require character offsets from the callers.\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-156901\n* gh-156926\n* gh-156927\n* gh-156928\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/serhiy-storchaka","@type":"Person","name":"serhiy-storchaka"},"datePublished":"2026-09-03T13:21:47Z","url":"https://github.com/python/cpython/issues/156894"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:48fb4964-749a-ba23-dea5-423b06dc9b4a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9374:928E2:32F782A:43F7101:6B01F799 |
| html-safe-nonce | 81fdac3bf5a30182b7816726585720b906e35a5e3c2f506911791b57e87f01f4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5Mzc0OjkyOEUyOjMyRjc4MkE6NDNGNzEwMTo2QjAxRjc5OSIsInZpc2l0b3JfaWQiOiI0Nzk4MjU5NzQ3NDUzMjY5OTEzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e0942af9ababa8af0a4ff8081a4a12644687dcd5b799aff125c8217a643fe287 |
| hovercard-subject-tag | issue:5337192378 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/156894/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b610b334e60ec743c549bc5a66ea2fd11387be96cd50ba305bcdb3b5020cadeb/python/cpython/issues/156894 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b610b334e60ec743c549bc5a66ea2fd11387be96cd50ba305bcdb3b5020cadeb/python/cpython/issues/156894 |
| og:image:alt | The tokenizer errors which report a range point at the wrong characters if the line contains non-ASCII characters before the error. >>> compile("aaaa = 00010", " |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | serhiy-storchaka |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width