Skip to content

assert-tuple

Pythoncorrectnessno fixdefault: warnpython/ruff

Reports an assert whose test is a tuple, usually the condition and the message written inside the parentheses.

A tuple with elements is always true, so assert (x > 0, "x must be positive") never fails, and the check looks like it is there. Python warns about it when the file is compiled.

To fix, write the message after a comma outside the parentheses: assert x > 0, "x must be positive".

Reported
x = 1
assert (x, "message")
assert x, "message"
assert (x)
assert ()
python:
lint:
rules:
assert-tuple: warn # off, warn (default), error

Enabled by the presets: python/ruff.

Suppress one line with sudsy-disable-next-line assert-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 F631 full