astral-sh / astral-sh/ruff

Formatter: different than black when wrapping parentheses for `assert`

Open
#8,331 1 comment 0 reactions 0 assignees View on GitHub
formatter
Dominant language
Rust
Stars
49.6k
Forks
2.4k
Avg merge
1d 21h
Merged PRs (30d)
435

Description

The ruff version is v0.1.3.

Original code:
```py
class SomeClass:
def some_method(necessary_key, kwargs):
assert set(necessary_key).issubset(set(kwargs)), "Must give neccessary key: %s" % ", ".join(necessary_key)
```

Black:
```py
class SomeClass:
def some_method(necessary_key, kwargs):
assert set(necessary_key).issubset(
set(kwargs)
), "Must give neccessary key: %s" % ", ".join(necessary_key)
```

ruff:

```py
class SomeClass:
def some_method(necessary_key, kwargs):
assert set(necessary_key).issubset(set(kwargs)), (
"Must give neccessary key: %s" % ", ".join(necessary_key)
)
```

See https://play.ruff.rs/f16cda56-ec7f-4b88-9dc9-1ba2dd18b39b

Contributor guide

Open the contributing guide

Research direction

Reproduce the assert example from the issue with Ruff v0.1.3 and compare its output with Black's output. Start from Ruff's formatter behavior for wrapped assert expressions; done means Ruff uses the expected parenthesis wrapping shown in the Black example and the behavior is covered against regression.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
tooling
Issue type
Bug
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.