useless-finally (RUF072)
Preview (since 0.15.8) · Related issues · View source
Fix is sometimes available.
This rule is unstable and in preview. The --preview flag is required for use.
What it does
Checks for finally clauses that only contain pass or ... statements
Why is this bad?
An empty finally clause is a no-op and adds unnecessary noise.
If the try statement has except or else clauses, the finally
clause can simply be removed. If it's a bare try/finally, the entire
try statement can be replaced with its body
Example
Use instead:
Example
Use instead:
See also
- [
needless-else][RUF047]: Removes emptyelseclauses ontry(and other statements). Both rules can fire on the sametrystatement - [
suppressible-exception][SIM105]: Rewritestry/except: passtocontextlib.suppress(). Won't apply while afinallyclause is present, so RUF072 must remove it first - [
useless-try-except][TRY203]: Flagstry/exceptthat only re-raises