Text of codeql.github.com › codeql-query-help › python › py-exit-from-finally as Styx crawled it on Nov 19, 2026. The page may have changed since. Only its words are kept, without pictures or layout.

Open the live page

‘break’ or ‘return’ statement in finally — CodeQL query help documentation

CodeQL query help documentation » CodeQL query help for Python » ‘break’ or ‘return’ statement in finally ¶ ID: py/exit-from-finally Kind: problem Security severity: Severity: warning Precision: medium Tags: - quality - reliability - error-handling - correctness - external/cwe/cwe-584 Query suites: - python-security-and-quality.qls Click to see the query in the CodeQL repository When a break or return statement is used in a finally block this causes the try-finally block to exit immediately discarding the exception.

This is unlikely to be the intention of the developer and makes the code more difficult to read. Recommendation ¶ Either move the break or return statement to immediately after the finally block or use an explicit except block to handle the exception. These modifications are behavior changing so you must take care to ensure that the resulting behavior is correct. References ¶ Python Language Reference: The try statement , The break statement , The return statement .

Common Weakness Enumeration: CWE-584 . © GitHub, Inc. Terms Privacy