A dict display gives the same key twice
What it finds
{"a": 1, "a": 2}: when a dict display gives the same key twice, the later value replaces the earlier one, which is then written for nothing. Keys are compared as Python compares them: strings and bytes by their values, so 'a' and "\x61" are the same key, and numbers by value, so 1, 1.0 and True are too. Only constants are compared; two names may hold different values.
From the rule's source, duplicate_dict_key.rs.
def table(name, other): return [ {"a": 1, "b": 2, "a": 3},tx0 reports: is given again, so its earlier value is lost {'x': 1, "x": 2},tx0 reports: is given again {"ab": 1, "a" "b": 2},tx0 reports: is given again {"\x41": 1, "A": 2},tx0 reports: is given again {1: "one", 1.0: "also one"},tx0 reports: the key 1.0 is given again {True: "yes", 1: "one"},tx0 reports: the key 1 is given again {0x10: 1, 16: 2},tx0 reports: the key 16 is given again {-1: 1, -1: 2},tx0 reports: the key -1 is given again {None: 1, None: 2},tx0 reports: the key None is given again {"a": 1, **other, "a": 2},tx0 reports: is given again {b"a": 1, "a": 2}, {name: 1, name: 2}, {1: 1, 2: 2, 1.5: 3}, {f"{name}": 1, f"{name}": 2}, ] 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:duplicate-dict-key" = "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:duplicate-dict-key] reason="..."tx0 explain tx0/python:duplicate-dict-key shows the same in the terminal. Found a false positive? Report it.