The save function
looked defensive.
def save_order(order):
try:
db.write(order)
finally:
log.info("save attempted")
return True
It always logged.
It always returned.
It always said True.
Even when the database
was down.
That is the trap.
A return inside finally
does not just return.
It throws away
whatever exception
was on its way out.
No traceback.
No error.
The caller
is told everything went fine.
The same goes for
break and continue
inside a finally
in a loop.
The exception
simply disappears.
Even a KeyboardInterrupt.
Even the error
that would have told you
the disk was full,
or the connection had gone,
or the order
was never written.
This has been
legal Python
for as long as finally
has existed.
It is also almost never
what anyone meant.
Here is what changed.
Python 3.14,
released in October 2025,
implements PEP 765.
Code where a return,
break or continue
would leave a finally block
now produces a SyntaxWarning.
The warning comes
when the file is compiled,
not when the line runs.
So you might see it
once
on a developer's laptop,
and never again,
because the compiled file
is cached.
Or you might never see it,
because warnings
scroll past in the build log
like weather.
This is the shape
of where things are going.
Languages are going back
over things they allowed
for decades,
and starting to say
this was probably a mistake.
They say it gently first.
A warning.
A note in the release.
Then they wait
to see who listened.
What to do,
before you upgrade:
Search your code
for return, break and continue
inside finally.
Linters already know.
Ruff and flake8-bugbear
flag it as B012.
Pylint calls it
lost-exception.
Turn the rule on
and fail the build.
Then rewrite each one.
Clean up in finally.
Return after it.
Let errors leave.
A function that cannot fail
is not robust.
It is a function
that has stopped
reporting.
– Serguey Asael Shinder
Top comments (1)
I ran your
save_orderon Python 3.14.4 withdb.writeraisingConnectionError. The output wassave attemptedand thenreturned: True. There was no traceback and rc was 0, so the exception disappeared exactly as you describe.I also checked your point about the cache, because it matters for anyone who plans to rely on the warning:
So even
-W errorwon't catch it once a.pycexists. A test run on a warm checkout or a cached CI image passes without a word. What did fail reliably was forcing a recompile:python -W error -m compileall -q -f src/exits 1 withSyntaxError: 'return' in a 'finally' block, whatever the cache state. That's a one-line CI step for teams that don't run Ruff's B012 yet. Running a file directly as a script (python save.py) also always warns, since__main__is never cached.Pyright already flags it as an error too ("A "return" cannot be used to exit a "finally" block"), so some editors were showing it before 3.14.
Did you find this one in a codebase that was already on 3.14, or while auditing before the upgrade?