Skip to content

gh-112943: Correctly compute end offsets for multiline tokens in the tokenize module #112949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 11, 2023

Conversation

pablogsal
Copy link
Member

@pablogsal pablogsal commented Dec 11, 2023

@@ -225,7 +225,7 @@ tokenizeriter_next(tokenizeriterobject *it)
col_offset = _PyPegen_byte_offset_to_character_offset(line, token.start - line_start);
}
if (token.end != NULL && token.end >= it->tok->line_start) {
end_col_offset = _PyPegen_byte_offset_to_character_offset(line, token.end - it->tok->line_start);
end_col_offset = _PyPegen_byte_offset_to_character_offset_raw(it->tok->line_start, token.end - it->tok->line_start);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it->tok->line_start holds the last line tokenised (the last line of the multi-line string) while line holds the entire multi-line string from the start to the end.

Co-authored-by: Serhiy Storchaka <[email protected]>
@pablogsal pablogsal enabled auto-merge (squash) December 11, 2023 11:24
@pablogsal pablogsal merged commit a135a6d into python:main Dec 11, 2023
@pablogsal pablogsal deleted the gh-112943 branch December 11, 2023 11:44
@miss-islington-app
Copy link

Thanks @pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@miss-islington-app
Copy link

Sorry, @pablogsal, I could not cleanly backport this to 3.12 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker a135a6d2c6d503b186695f01efa7eed65611b04e 3.12

@bedevere-app
Copy link

bedevere-app bot commented Dec 11, 2023

GH-112957 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 only security fixes label Dec 11, 2023
pablogsal added a commit to pablogsal/cpython that referenced this pull request Dec 11, 2023
…okens in the tokenize module (pythonGH-112949)

(cherry picked from commit a135a6d)

Co-authored-by: Pablo Galindo Salgado <[email protected]>
pablogsal added a commit that referenced this pull request Dec 11, 2023
…in the tokenize module (GH-112949) (#112957)

(cherry picked from commit a135a6d)
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants