An assertion tests a tuple, which is always true
What it finds
assert (x > 0, "x must be positive"): the parentheses make the condition and the message one tuple, and a tuple that is not empty is always true, so the assertion never fails. CPython warns about it when it compiles it.
For a pair, the fix removes the parentheses so that the second element becomes the message. It is unsafe, since the assertion then starts to check its condition.
From the rule's source, assert_tuple.rs.
def check(x, items): assert (x > 0, "x must be positive")tx0 reports: this assertion never fails assert (x,)tx0 reports: this assertion never fails assert x > 0, "x must be positive" assert (x > 0), "x must be positive" assert () assert items == (1, 2) Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/python:assert-tuple" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
# tx0: ignore[tx0/python:assert-tuple] reason="..."tx0 explain tx0/python:assert-tuple shows the same in the terminal. Found a false positive? Report it.