mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-28 02:39:50 +00:00
## Summary
Format `ExprIfExp`, also known as the ternary operator or inline `if`.
It can look like
```python
a1 = 1 if True else 2
```
but also
```python
b1 = (
# We return "a" ...
"a" # that's our True value
# ... if this condition matches ...
if True # that's our test
# ... otherwise we return "b§
else "b" # that's our False value
)
```
This also fixes a visitor order bug.
The jaccard index on django goes from 0.911 to 0.915.
## Test Plan
I added fixtures without and with comments in strange places.
|
||
|---|---|---|
| .. | ||
| flake8_to_ruff | ||
| ruff | ||
| ruff_benchmark | ||
| ruff_cache | ||
| ruff_cli | ||
| ruff_dev | ||
| ruff_diagnostics | ||
| ruff_formatter | ||
| ruff_index | ||
| ruff_macros | ||
| ruff_python_ast | ||
| ruff_python_formatter | ||
| ruff_python_resolver | ||
| ruff_python_semantic | ||
| ruff_python_stdlib | ||
| ruff_python_whitespace | ||
| ruff_rustpython | ||
| ruff_textwrap | ||
| ruff_wasm | ||