A ternary x if c else y holds another ternary
What it finds
a if x else b if y else c: conditional expressions inside each other are read left to right but evaluated by precedence, which few readers keep straight. An if statement, or a lookup table, shows the cases one by one.
From the rule's source, conditional_inside_conditional.rs.
def pick(a, b, x, y): first = a if x else b if y else Nonetx0 reports: this conditional expression has another one inside it second = (a if x else b) if y else Nonetx0 reports: this conditional expression has another one inside it third = a if x else b return first, second, third 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:
[rules]
"tx0/python:conditional-inside-conditional" = "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:conditional-inside-conditional] reason="..."tx0 explain tx0/python:conditional-inside-conditional shows the same in the terminal. Found a false positive? Report it.