Fix UTF-8 offsets in sequence patterns - #873
Open
yangfan-yf-yf wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
I reproduced a crash on
master(f005ac786da7d556fdf5733e9b9ddae1eaf27242) when patching a sequence pattern containing non-ASCII text:The walker reads
:as the closing delimiter and raisesMismatchedTokenError. Nested and empty sequence patterns after non-ASCII text are also affected, and some inputs produce incorrect source regions without raising.AST columns are UTF-8 byte offsets, while the walker slices a Python string using character offsets. I convert the AST coordinates at the sequence-pattern slicing sites, including the empty-pattern path. The generic
SourceLinesAdaptercoordinate behavior is preserved.The regression test covers seven patterns, including non-ASCII captures and literals, nested and empty sequences, bare sequences, and multiline input. It checks both source round-tripping and each sequence node's source region against
ast.get_source_segment.Related to #623; follows the sequence delimiter handling introduced in #863. Delimiter warnings for adjacent comments remain outside this change.
Validation on Windows / Python 3.12.14:
git diff --checkpass.Checklist