mirror of https://github.com/astral-sh/ruff
**Summary** Break slices at the colon first, since the colon is separator with the lowest precedence and we're in a parenthesized context.
**Input**
```python
section_header_data = byte_array[byte_begin_index + byte_step_index * event_index : byte_begin_index + byte_step_index * (event_index + 1)]
```
**Black**
```python
section_header_data = byte_array[
byte_begin_index
+ byte_step_index * event_index : byte_begin_index
+ byte_step_index * (event_index + 1)
]
```
**Current formatting**
```python
section_header_data = byte_array[
byte_begin_index + byte_step_index * event_index : byte_begin_index
+ byte_step_index * (event_index + 1)
]
```
**Proposed formatting**
```python
section_header_data = byte_array[
byte_begin_index + byte_step_index * event_index
: byte_begin_index + byte_step_index * (event_index + 1)
]
```
This is another intentional black deviation, but i find it a clear style improvement.
This is consistent with adding a step:
```python
section_header_data2 = byte_array[
byte_begin_index + byte_step_index * event_index
: byte_begin_index + byte_step_index
: section_size
]
```
As-is, this regresses trailing colon comments:
**in**
```python
c1 = "c"[
1: # e
# f
2
]
```
**out**
```python
c1 = "c"[
1
: # e
# f
2
]
```
Fixes #7316
**Test Plan** Added the fixtures above.
|
||
|---|---|---|
| .. | ||
| flake8_to_ruff | ||
| ruff | ||
| ruff_benchmark | ||
| ruff_cache | ||
| ruff_cli | ||
| ruff_dev | ||
| ruff_diagnostics | ||
| ruff_formatter | ||
| ruff_index | ||
| ruff_macros | ||
| ruff_notebook | ||
| ruff_python_ast | ||
| ruff_python_codegen | ||
| ruff_python_formatter | ||
| ruff_python_index | ||
| ruff_python_literal | ||
| ruff_python_parser | ||
| ruff_python_resolver | ||
| ruff_python_semantic | ||
| ruff_python_stdlib | ||
| ruff_python_trivia | ||
| ruff_shrinking | ||
| ruff_source_file | ||
| ruff_text_size | ||
| ruff_wasm | ||
| ruff_workspace | ||