The truth value of NotImplemented is taken

tx0/python:not-implemented-truthdefaultwarningbug

What it finds

if NotImplemented:, NotImplemented or fallback: NotImplemented is the value comparison and arithmetic methods return to let the other operand try. Its truth value was always true, has been deprecated since Python 3.9 and raises TypeError since Python 3.14. A condition on it never means what it says.

Reported is the name NotImplemented, as the builtin, used as a condition of if, elif, while, assert or a conditional expression, or as an operand of not, and or or.

From the rule's source, not_implemented_truth.rs.

Example from the rule's tests
def merge(left, right, fallback):    result = left.__add__(right)    if NotImplemented:tx0 reports: NotImplemented is used as a truth value        return fallback    value = NotImplemented or fallbacktx0 reports: NotImplemented is used as a truth value    if result is NotImplemented:        return fallback    return value or NotImplemented
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:not-implemented-truth" = "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:not-implemented-truth] reason="..."

tx0 explain tx0/python:not-implemented-truth shows the same in the terminal. Found a false positive? Report it.