Fix unicode handling in patched ast - #872
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #872 +/- ##
==========================================
+ Coverage 95.29% 95.33% +0.04%
==========================================
Files 134 134
Lines 26541 26779 +238
==========================================
+ Hits 25291 25530 +239
+ Misses 1250 1249 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
lieryan
force-pushed
the
lieryan-implement-ast-lines-adapter
branch
2 times, most recently
from
September 7, 2026 03:17
17a258f to
a6e3025
Compare
ASTLinesAdapter uses ast-produced col_offset/end_col_offset which are produced by the python's own parser to calculate convert offsets to str offset, which should be more reliable than the ad-hoc calculations that generally would only have worked with ASCII-only source code.
col_offset/end_col_offset uses utf-8 offset which generally only accidentally coincides with str-offset that rope uses as node.region. ASTLinesAdapter ensures correct computation of offset.
All slices are handled by __getitem__() since Python 3.
Now we have a better ASTLinesAdapter that actually handles unicode correctly.
lieryan
force-pushed
the
lieryan-implement-ast-lines-adapter
branch
from
September 15, 2026 12:53
a6e3025 to
327ebad
Compare
The vast majority of Python source code is going to be mostly ascii-only text, we can completely skip the entire unicode encode/decode overhead when there's only ascii characters.
This matches the behavior of ast.get_source_segment().
lieryan
force-pushed
the
lieryan-implement-ast-lines-adapter
branch
from
September 15, 2026 14:37
327ebad to
c2bd6a4
Compare
lieryan
force-pushed
the
lieryan-implement-ast-lines-adapter
branch
from
September 15, 2026 14:40
c2bd6a4 to
acf6100
Compare
2 tasks
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
Please include a summary of the change and which issue is fixed.
Checklist (delete if not relevant):