A local variable is assigned but never read
What it finds
result = compute() in a function, with result never read: either the value was meant to be used and is not, or the assignment is left over. Only the call needs to stay.
Reported are local variables of functions that are only ever assigned, never read, not even by a nested function. Left alone are names starting with _, names bound by unpacking several targets, as in key, _value = item, and functions that call locals(), vars(), eval or exec, which can read any local.
From the rule's source, unused_variable.rs.
def compute(items, log): total = sum(items)tx0 reports: total is assigned but never read count = len(items) first, rest = items[0], items[1:] _ignored = log() result = 0tx0 reports: result is assigned but never read result = count + 1 def inner(): return count return inner, rest def dynamic(): value = 1 return locals() TOTAL = 0 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:unused-variable" = "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:unused-variable] reason="..."tx0 explain tx0/python:unused-variable shows the same in the terminal. Found a false positive? Report it.