astral-sh / astral-sh/ruff

Formatting of call argument split on operator reduces readability

Open
#8,261 0 comments 0 reactions 0 assignees View on GitHub
formatter style
Dominant language
Rust
Stars
49.6k
Forks
2.4k
Avg merge
2d 1h
Merged PRs (30d)
458

Description

The following code is formatted the same with `black`, `black --preview`, and `ruff format`:

```python
if True:
# Limit the number of items displayed per rule to between 10 and 200
max_display_per_rule = max(
10,
200
// len(
set(all_rule_changes.added_violations.keys()).union(
all_rule_changes.removed_violations.keys()
)
),
)
```

Moving the operator onto a new line makes it look like an argument in the function call.

Perhaps the following would be clearer?

```python
if True:
# Limit the number of items displayed per rule to between 10 and 200
max_display_per_rule = max(
10,
200 // len(
set(all_rule_changes.added_violations.keys()).union(
all_rule_changes.removed_violations.keys()
)
),
)
```

Contributor guide

Open the contributing guide

Research direction

Use the two Python examples in issue #8261 as the starting point and inspect Ruff's formatter behavior for operators inside split call arguments. Compare the current output with the proposed output and add or update a regression test if the formatter test suite provides one; done means the operator remains on the expression line as shown in the second example.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.