defaultdict gets its factory as default_factory=, which becomes a dict entry
What it finds
defaultdict(default_factory=list): defaultdict takes its factory by position only, and passes keyword arguments on to dict, so this makes a plain dict with the single entry "default_factory": list and no factory. Missing keys then raise KeyError.
From the rule's source, defaultdict_factory_keyword.rs.
import collectionsfrom collections import defaultdict def groups(): a = defaultdict(default_factory=list)tx0 reports: default_factory= becomes a dict entry here, and the defaultdict has no factory b = defaultdict(list) c = defaultdict(list, default_factory=1) d = collections.defaultdict(default_factory=int)tx0 reports: default_factory= becomes a dict entry e = defaultdict(list, a=[1]) return a, b, c, d, e 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:defaultdict-factory-keyword" = "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:defaultdict-factory-keyword] reason="..."tx0 explain tx0/python:defaultdict-factory-keyword shows the same in the terminal. Found a false positive? Report it.