gh-149277: Fix error position for invalid numeric literals#149456
gh-149277: Fix error position for invalid numeric literals#149456anujbharambe wants to merge 3 commits intopython:mainfrom
Conversation
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Documentation build overview
18 files changed ·
|
|
I have made the requested changes; please review again. Added |
|
Thanks for making the requested changes! @picnixz: please review the changes made to this pull request. |
Summary
Fix the
SyntaxErrorcaret position for invalid numeric literals. Previously,the caret pointed at the last valid digit instead of the first invalid character.
For example,
0x9gnow correctly shows:0x9g
^
SyntaxError: invalid hexadecimal literal
Instead of the previous incorrect output:
0x9g
^
SyntaxError: invalid hexadecimal literal
The issue was a spurious
tok_backup(tok, c)call inverify_end_of_number()in the error branch. Since
_PyTokenizer_syntaxerrorcomputes the column offsetfrom
tok->cur, backing up one character caused the caret to point at thepreceding (valid) character. Removing the backup keeps
tok->curat the correctposition.
Fixes #149277