The result of a call that has no other effect is dropped
What it finds
sorted(items), map(print, names), ", ".join(parts) on a line of their own: these calls change nothing and only return something, and the result is dropped. sorted returns a new list where items.sort() sorts in place; map, filter, zip, and enumerate are lazy and do nothing until iterated; strings cannot change, so their methods return new strings.
Reported are those builtins, and methods called directly on a string literal, as expression statements. encode and decode on a literal are left alone, since they are a way to check that a codec exists.
From the rule's source, discarded_result.rs.
def tidy(items, names, parts): sorted(items)tx0 reports: sorted returns a new list, and its result is dropped here, so this does nothing map(print, names)tx0 reports: map is lazy, and its result is dropped here ", ".join(parts)tx0 reports: strings do not change, so the string join returns is lost here items.sort() print(sorted(items)) names.strip() return items 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:discarded-result" = "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:discarded-result] reason="..."tx0 explain tx0/python:discarded-result shows the same in the terminal. Found a false positive? Report it.