ruff/crates
Dhruv Manilawala 33ac2867b7
Use non-parenthesized range for DebugText (#9953)
## Summary

This PR fixes the `DebugText` implementation to use the expression range
instead of the parenthesized range.

Taking the following code snippet as an example:
```python
x = 1
print(f"{  ( x  ) = }")
```

The output of running it would be:
```
  ( x  ) = 1
```

Notice that the whitespace between the parentheses and the expression is
preserved as is.

Currently, we don't preserve this information in the AST which defeats
the purpose of `DebugText` as the main purpose of the struct is to
preserve whitespaces _around_ the expression.

This is also problematic when generating the code from the AST node as
then the generator has no information about the parentheses the
whitespaces between them and the expression which would lead to the
removal of the parentheses in the generated code.

I noticed this while working on the f-string formatting where the debug
text would be used to preserve the text surrounding the expression in
the presence of debug expression. The parentheses were being dropped
then which made me realize that the problem is instead in the parser.

## Test Plan

1. Add a test case for the parser
2. Add a test case for the generator
2024-02-12 23:00:02 +05:30
..
ruff Allow arbitrary configuration options to be overridden via the CLI (#9599) 2024-02-09 21:56:37 +00:00
ruff_benchmark Run doctests as part of CI pipeline (#9939) 2024-02-12 10:18:58 +01:00
ruff_cache Make all dependencies workspace dependencies (#9333) 2024-01-02 13:41:59 +00:00
ruff_dev Allow arbitrary configuration options to be overridden via the CLI (#9599) 2024-02-09 21:56:37 +00:00
ruff_diagnostics Run doctests as part of CI pipeline (#9939) 2024-02-12 10:18:58 +01:00
ruff_formatter Use Rust 1.76 (#9897) 2024-02-08 18:20:08 +00:00
ruff_index Run doctests as part of CI pipeline (#9939) 2024-02-12 10:18:58 +01:00
ruff_linter [perflint] Catch a wider range of mutations in PERF101 (#9955) 2024-02-12 12:17:55 -05:00
ruff_macros Run doctests as part of CI pipeline (#9939) 2024-02-12 10:18:58 +01:00
ruff_notebook Run doctests as part of CI pipeline (#9939) 2024-02-12 10:18:58 +01:00
ruff_python_ast [perflint] Catch a wider range of mutations in PERF101 (#9955) 2024-02-12 12:17:55 -05:00
ruff_python_codegen Use non-parenthesized range for DebugText (#9953) 2024-02-12 23:00:02 +05:30
ruff_python_formatter Docstring formatting: Preserve tab indentation when using indent-style=tabs (#9915) 2024-02-12 16:09:13 +01:00
ruff_python_index Run doctests as part of CI pipeline (#9939) 2024-02-12 10:18:58 +01:00
ruff_python_literal Run doctests as part of CI pipeline (#9939) 2024-02-12 10:18:58 +01:00
ruff_python_parser Use non-parenthesized range for DebugText (#9953) 2024-02-12 23:00:02 +05:30
ruff_python_resolver Run doctests as part of CI pipeline (#9939) 2024-02-12 10:18:58 +01:00
ruff_python_semantic Run doctests as part of CI pipeline (#9939) 2024-02-12 10:18:58 +01:00
ruff_python_stdlib Slight speed-up for lowercase and uppercase identifier checks (#9798) 2024-02-03 14:40:41 +00:00
ruff_python_trivia Add fast-path for comment detection (#9808) 2024-02-05 11:00:18 -05:00
ruff_shrinking Bump version to v0.2.1 (#9843) 2024-02-05 15:31:05 -05:00
ruff_source_file Fix blank-line docstring rules for module-level docstrings (#9878) 2024-02-07 16:48:28 -05:00
ruff_text_size Range formatting: Fix invalid syntax after parenthesizing expression (#9751) 2024-02-02 17:56:25 +01:00
ruff_wasm Run doctests as part of CI pipeline (#9939) 2024-02-12 10:18:58 +01:00
ruff_workspace Stabilize quote-style preserve (#9922) 2024-02-12 09:30:07 +00:00