An assertion tests a non-empty string or display, which is always true

tx0/python:assert-always-truedefaultwarningbug

What it finds

assert "user is logged in", assert [x > 0]: a non-empty string, list, set or dict is always true, so the assertion never fails. Usually the condition was left out in front of the message, as in assert logged_in, "user is logged in".

Tuples are reported by another rule. Empty literals, which make the assertion always fail on purpose, are left alone.

From the rule's source, assert_always_true.rs.

Example from the rule's tests
def check(user, items):    assert "user is logged in"tx0 reports: this assertion tests a non-empty string, which is always true, so it never fails    assert [x > 0 for x in items] or True    assert [user]tx0 reports: this assertion tests a non-empty display, which is always true    assert user, "user is logged in"    assert ""    assert []
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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:

tx0.toml
[rules]
"tx0/python:assert-always-true" = "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-always-true] reason="..."

tx0 explain tx0/python:assert-always-true shows the same in the terminal. Found a false positive? Report it.