Summary
When unnecessary-if (RUF050) keeps the if condition, it can change behavior or introduce a syntax error, if the condition takes multiple lines and wouldn’t be parsed as a single expression outside its original context. The solution is to add parentheses around certain multiline expressions. Example:
$ cat >ruf050.py <<'# EOF'
if (
id(0)
+ 0
):
pass
# EOF
$ ruff --isolated check ruf050.py --select RUF050 --preview --fix
error: Fix introduced a syntax error. Reverting all changes.
This indicates a bug in Ruff. If you could open an issue at:
https://github.com/astral-sh/ruff/issues/new?title=%5BFix%20error%5D
...quoting the contents of `ruf050.py`, the rule codes RUF050, along with the `pyproject.toml` settings and executed command, we'd be very appreciative!
error[RUF050]: Empty `if` statement
--> ruf050.py:1:1
|
1 | / if (
2 | | id(0)
3 | | + 0
4 | | ):
5 | | pass
| |________^
|
help: Remove the `if` statement
- if (
- id(0)
1 + id(0)
2 | + 0
- ):
- pass
Found 1 error.
[*] 1 fixable with the `--fix` option.
Version
ruff 0.15.8 (c2a8815 2026-03-26)
Summary
When
unnecessary-if(RUF050) keeps theifcondition, it can change behavior or introduce a syntax error, if the condition takes multiple lines and wouldn’t be parsed as a single expression outside its original context. The solution is to add parentheses around certain multiline expressions. Example:Version
ruff 0.15.8 (c2a8815 2026-03-26)