A literal is called, searched with in or indexed, which its type does not support
What it finds
("a", 1) ("b", 2) in a list, x in 5, None[0]: a literal is called, searched or indexed although its type does not allow it, and Python raises TypeError. A call of a tuple or string literal usually means a comma is missing between two items of a list.
Reported are calls of string, number, None, tuple, list, dict and set literals and displays, in and not in with a number, None, True or False on the right, and subscripts of numbers and None.
From the rule's source, literal_misuse.rs.
def table(x, items): rows = [ ("a", 1)tx0 reports: a tuple is called, which raises TypeError; a comma may be missing before the parentheses ("b", 2), ] if x in 5:tx0 reports: an int cannot be searched with in, so this raises TypeError return rows if x in None:tx0 reports: None cannot be searched with in return items first = None[0]tx0 reports: None cannot be indexed, so this raises TypeError return first, "-".join(items), x in "abc", (lambda: 1)() 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:literal-misuse" = "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:literal-misuse] reason="..."tx0 explain tx0/python:literal-misuse shows the same in the terminal. Found a false positive? Report it.