An operator combines two literals of types that do not support it
What it finds
"total: " + 3, [1, 2] + (3,), "ab" - "b": arithmetic between literals of types that do not support it raises TypeError when the line runs. Usually a value was meant to be converted, as in "total: " + str(3), or an f-string was meant.
Checked are +, -, * and / between two operands written as literals or displays, whose types Python knows not to combine.
From the rule's source, incompatible_literal_operands.rs.
def show(count): a = "total: " + 3tx0 reports: + between a string and an int raises TypeError b = [1, 2] + (3,)tx0 reports: + between a list and a tuple raises TypeError c = "ab" - "b"tx0 reports: - between a string and a string raises TypeError d = "ab" * 2.5tx0 reports: * between a string and a float raises TypeError e = "ab" * 3 + "c" f = 1 + 2.5 g = {1} - {2} h = "total: " + str(count) return a, b, c, d, e, f, g, h 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:incompatible-literal-operands" = "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:incompatible-literal-operands] reason="..."tx0 explain tx0/python:incompatible-literal-operands shows the same in the terminal. Found a false positive? Report it.