Skip to content

raise-without-from-inside-except

Pythonsuspiciousno fixdefault: off

Reports a raise of an exception inside an except clause without from. Nested if, loops, with and match are part of the clause; a nested try, function or class is not. Raising the name the clause bound is not reported.

Without from, the traceback says “During handling of the above exception, another exception occurred”, which reads as a bug in the handler. from err says that this exception is the result of that one, and from None hides the first one on purpose.

To fix, add from err, or from None.

Reported
...
pass
except OSError as e:
if x:
raise ValueError("nested")
try:
raise ValueError("try body")
except KeyError:
raise ValueError("inner handler")
...
raise ValueError() from e
raise ValueError() from None
...
try:
pass
except* OSError:
raise ValueError
python:
lint:
rules:
raise-without-from-inside-except: warn # off (default), warn, error

Suppress one line with sudsy-disable-next-line raise-without-from-inside-except in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
ruff B904 full