Version-Specific Features

Python 3.14 — Warnings for escaping finally blocks

CPython 3.14 emits a SyntaxWarning for control flow that exits a finally block, because it can discard an exception or override a return value. Move the return outside cleanup or let the original exception propagate. Requires Python 3.14 or the relevant build; example is not executed locally.

Formal Syntax & Structure

python syntaxpython
return / break / continue leaving finally

Return Value

Feature-specific

No single return type; see the example and feature description.

Working Example

Example Snippetpython
# Intentionally diagnostic: compile but do not execute.compile('def f():\n    try:\n        raise ValueError()\n    finally:\n        return 1\n', '<demo>', 'exec')
Python Reference