A group iterator from itertools.groupby is stored for later, though it is emptied when the loop moves to the next group
What it finds
The groups that groupby hands out share the underlying iterator; advancing to the next key exhausts the previous group. Appending the group itself to a list or storing it in a dict keeps an iterator that yields nothing later. list(group) keeps the items.
From the rule's source, groupby_group_stored.rs.
import itertools def groups(items): out = [] by_key = {} for key, group in itertools.groupby(items): out.append(group)tx0 reports: this group is empty once the loop moves on by_key[key] = grouptx0 reports: this group is empty once the loop moves on kept = list(group) return out, by_key, kept Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/python:groupby-group-stored" = "warning"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:groupby-group-stored] reason="..."tx0 explain tx0/python:groupby-group-stored shows the same in the terminal. Found a false positive? Report it.