Every return of a function gives the same literal, so the result tells the caller nothing

tx0/python:same-literal-every-returnstrictwarningmaintainability/duplicationdepth fastmaintainability

What it finds

A function with several return statements that all hand back the same constant computes nothing for its caller; either the paths were meant to return different values, or the result can go. None is left alone, as are functions with a single return.

From the rule's source, same_literal_every_return.rs.

Example from the rule's tests
def check(x):tx0 reports: every return of this function gives the same value    if x > 1:        return True    if x < 0:        return True    return True def varies(x):    if x > 1:        return 1    if x < 0:        return 2    return 1 def nothing(x):    if x:        return None    if not x:        return None    return None
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 from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/python:same-literal-every-return" = "warning"

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:same-literal-every-return] reason="..."

tx0 explain tx0/python:same-literal-every-return shows the same in the terminal. Found a false positive? Report it.