-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Closed
Copy link
Labels
bugSomething isn't workingSomething isn't workingformatterRelated to the formatterRelated to the formatter
Description
Summary
Given ex.py with content:
x =7
try:
a;
finally:
bWe get:
❯ ruff format --range=2 --diff ex.py
error: Failed to format tarmin.py: syntax error: Expected the keyword token but found another token instead.This only happens with range formatting, since it comes from this call of self.range:
ruff/crates/ruff_python_formatter/src/statement/clause.rs
Lines 368 to 373 in eb8c0ad
| // Write a source map entry for the colon for range formatting to support formatting the clause header without | |
| // the clause body. Avoid computing `self.header.range()` otherwise because it's somewhat involved. | |
| let clause_end = if f.options().source_map_generation().is_enabled() { | |
| Some(source_position( | |
| self.header.range(f.context().source())?.end(), | |
| )) |
The SimpleTokenizer finding the keyword range is expecting to find Finally but instead it finds the (unnecessary) semi-colon.
Version
No response
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingformatterRelated to the formatterRelated to the formatter