[parser] Fix indentation tracking after line continuations#23417
Merged
dhruvmanila merged 4 commits intomainfrom Feb 19, 2026
Merged
[parser] Fix indentation tracking after line continuations#23417dhruvmanila merged 4 commits intomainfrom
dhruvmanila merged 4 commits intomainfrom
Conversation
Per the Python spec, the whitespace up to the first backslash determines the line's indentation, and continuation lines should not affect the indentation level. The lexer's `eat_indentation` loop was not handling this: after a `\` continuation, it accumulated the continuation line's whitespace into the indentation, causing spurious IndentationError and "Expected a statement" errors. Fix: after consuming `\<newline>` during indentation tracking, skip the continuation line's whitespace with `eat_while(is_python_whitespace)` without accumulating it into `indentation`. Guard: only skip when `indentation != Indentation::root()` — when `\` is at column 0, let the loop continue so the next line's whitespace is accumulated normally. Lexer snapshot tests cover: basic continuation in indented block, continuation at column 0, multiple consecutive continuations, and mismatched indentation error — each with all three EOL types. Ref: https://docs.python.org/3/reference/lexical_analysis.html#indentation See: python/cpython#90249
knutwannheden
pushed a commit
to openrewrite/ruff
that referenced
this pull request
Feb 20, 2026
…#23417) ## Summary fixes: astral-sh#19301 ## Test Plan Add new lexer and parser test cases. --------- Co-authored-by: Kartik Ganapathi <kartikganapathi@icloud.com>
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.
Summary
fixes: #19301
Test Plan
Add new lexer and parser test cases.