raise-without-from-inside-except
What it does
Section titled “What it does”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.
Why it matters
Section titled “Why it matters”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.
Example
Section titled “Example”... passexcept 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: passexcept* OSError: raise ValueErrorConfiguration
Section titled “Configuration”python: lint: rules: raise-without-from-inside-except: warn # off (default), warn, errorSuppress one line with sudsy-disable-next-line raise-without-from-inside-except in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| ruff | B904 |
full |