ruff/crates/ruff_python_formatter/src/other
Charlie Marsh c71ff7eae1
Avoid printing continuations within import identifiers (#7744)
## Summary

It turns out that _some_ identifiers can contain newlines --
specifically, dot-delimited import identifiers, like:
```python
import foo\
    .bar
```

At present, we print all identifiers verbatim, which causes us to retain
the `\` in the formatted output. This also leads to violating some debug
assertions (see the linked issue, though that's a symptom of this
formatting failure).

This PR adds detection for import identifiers that contain newlines, and
formats them via `text` (slow) rather than `source_code_slice` (fast) in
those cases.

Closes https://github.com/astral-sh/ruff/issues/7734.

## Test Plan

`cargo test`
2023-10-02 09:51:07 -04:00
..
alias.rs Avoid printing continuations within import identifiers (#7744) 2023-10-02 09:51:07 -04:00
arguments.rs Don't reorder parameters in function calls (#7268) 2023-09-13 09:01:49 +00:00
commas.rs Improve with statement comment handling and expression breaking (#6621) 2023-08-18 03:30:38 +00:00
comprehension.rs Attach dangling comments to the comprehension instead of the if or iter nodes (#7693) 2023-09-29 10:45:01 +01:00
decorator.rs Introduce Token element (#7048) 2023-09-02 10:05:47 +02:00
elif_else_clause.rs Use the formatter prelude in more files (#6882) 2023-08-25 16:51:07 -04:00
except_handler_except_handler.rs Introduce Token element (#7048) 2023-09-02 10:05:47 +02:00
identifier.rs Avoid printing continuations within import identifiers (#7744) 2023-10-02 09:51:07 -04:00
keyword.rs Introduce Token element (#7048) 2023-09-02 10:05:47 +02:00
match_case.rs Introduce Token element (#7048) 2023-09-02 10:05:47 +02:00
mod.rs Improve with statement comment handling and expression breaking (#6621) 2023-08-18 03:30:38 +00:00
parameter.rs Introduce Token element (#7048) 2023-09-02 10:05:47 +02:00
parameter_with_default.rs Introduce Token element (#7048) 2023-09-02 10:05:47 +02:00
parameters.rs Introduce Token element (#7048) 2023-09-02 10:05:47 +02:00
with_item.rs Prefer preserving WithItem parentheses (#7694) 2023-09-28 14:42:40 +01:00