ruff/crates/ruff_python_formatter/src
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
..
comments Attach dangling comments to the comprehension instead of the if or iter nodes (#7693) 2023-09-29 10:45:01 +01:00
expression Use Expr::is_* methods in more matches (#7714) 2023-09-29 17:28:50 +00:00
module Attach dangling comments to the comprehension instead of the if or iter nodes (#7693) 2023-09-29 10:45:01 +01:00
other Avoid printing continuations within import identifiers (#7744) 2023-10-02 09:51:07 -04:00
pattern Attach dangling comments to the comprehension instead of the if or iter nodes (#7693) 2023-09-29 10:45:01 +01:00
snapshots Remove exception-handler lexing from unused-bound-exception fix (#5851) 2023-07-18 18:27:46 +00:00
statement Avoid printing continuations within import identifiers (#7744) 2023-10-02 09:51:07 -04:00
type_param Introduce Token element (#7048) 2023-09-02 10:05:47 +02:00
builders.rs Introduce Token element (#7048) 2023-09-02 10:05:47 +02:00
cli.rs Add support for PEP 701 (#7376) 2023-09-29 02:55:39 +00:00
context.rs Implement DerefMut for WithNodeLevel (#6443) 2023-08-11 10:41:48 +00:00
generated.rs Introduce AST nodes for PatternMatchClass arguments (#6881) 2023-08-26 14:45:44 +00:00
lib.rs Attach dangling comments to the comprehension instead of the if or iter nodes (#7693) 2023-09-29 10:45:01 +01:00
main.rs Formatter and parser refactoring (#7569) 2023-09-26 15:29:43 +02:00
options.rs Add most formatter options to ruff.toml / pyproject.toml (#7566) 2023-09-22 15:47:57 +00:00
prelude.rs Accept any Into<AnyNodeRef> as Comments arguments (#5205) 2023-06-20 16:49:21 +00:00
verbatim.rs Memoize text width (#6552) 2023-09-06 07:10:13 +00:00