Code that can never run
What it finds
Statements after return, raise, break or continue in the same block never run.
A yield after a return, as in return followed by yield, is the way to write a generator that yields nothing: it never runs, but it makes the function a generator, so it is not reported. Blocks the parser could not read completely are skipped.
From the rule's source, unreachable_code.rs.
def first(items, log): for item in items: if item: break log(item)tx0 reports: this code is never reached continue log("next")tx0 reports: this code is never reached return items log("done")tx0 reports: this code is never reached log("again") def fail(message): raise ValueError(message) return Nonetx0 reports: this code is never reached def empty(): return yield def guarded(items): if items: return items return [] 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:unreachable-code" = "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:unreachable-code] reason="..."tx0 explain tx0/python:unreachable-code shows the same in the terminal. Found a false positive? Report it.