Every except clause of a try raises the caught exception again unchanged

tx0/python:useless-reraiserecommendedwarningsmell

What it finds

try: ... except ValueError: raise with nothing else: catching an exception only to raise it again as it was does the same as not catching it, and makes readers look for a reason that is not there.

Reported is a try statement whose every handler only re-raises, with a bare raise or raise e of its own name, and that has no else or finally. When another handler does something, a re-raising handler before it keeps those exceptions from reaching it, which is a reason to have it.

From the rule's source, useless_reraise.rs.

Example from the rule's tests
def load(path):    try:        return open(path).read()    except OSError:tx0 reports: this handler raises what it caught unchanged, which is the same as not catching it        raise  def parse(text):    try:        return int(text)    except ValueError as exc:tx0 reports: this handler raises what it caught unchanged        raise exc  def guarded(text):    try:        return int(text)    except ValueError:        raise    except Exception:        return None
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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:

tx0.toml
[rules]
"tx0/python:useless-reraise" = "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:useless-reraise] reason="..."

tx0 explain tx0/python:useless-reraise shows the same in the terminal. Found a false positive? Report it.