Skip to content

if-tuple

Pythoncorrectnessno fixdefault: warnpython/ruff

Reports an if or elif whose test is a tuple.

A tuple with elements is always true (and an empty one always false), so the branch is always taken. It is usually a stray comma, or a condition written inside parentheses with commas instead of and.

To fix, write one boolean expression.

Reported
x = y = 1
if (x, y):
pass
elif (x, y):
pass
elif (x):
pass
...
python:
lint:
rules:
if-tuple: warn # off, warn (default), error

Enabled by the presets: python/ruff.

Suppress one line with sudsy-disable-next-line if-tuple 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 F634 full