Skip to content

if-with-same-arms

Pythonstyleno fixdefault: offpython/ruff

Reports two neighbouring branches of an if/elif chain whose bodies are the same.

Two branches that do the same thing are one branch with a condition joined by or. Written twice, a later change is made to one and not the other.

To fix, join the conditions with or.

Reported
...
...
x = 1
elif b:
x = 1
...
python:
lint:
rules:
if-with-same-arms: warn # off (default), warn, error

Enabled by the presets: python/ruff.

Suppress one line with sudsy-disable-next-line if-with-same-arms in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
ruff SIM114 full