A list, dict or set is written as a dict key or set member
What it finds
{[1, 2]: "pair"}, {{"a": 1}}: dict keys and set members must be hashable, and lists, dicts and sets are not, so evaluating the display raises TypeError. A tuple or a frozenset is the hashable form.
Reported are list, dict and set displays and comprehensions written as a key of a dict display or comprehension, or as a member of a set display or comprehension.
From the rule's source, unhashable_literal.rs.
def tables(a, b): pairs = {[a, b]: 1}tx0 reports: a list cannot be a dict key, so this raises TypeError groups = {{a}, frozenset(b)}tx0 reports: a set cannot be a set member nested = {(a, b): {a: [b]}} built = {[x] for x in a}tx0 reports: a list cannot be a set member return pairs, groups, nested, built 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:unhashable-literal" = "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:unhashable-literal] reason="..."tx0 explain tx0/python:unhashable-literal shows the same in the terminal. Found a false positive? Report it.