‘break’ or ‘return’ statement in finally¶
ID: py/exit-from-finally Kind: problem Severity: warning Precision: medium Tags: - reliability - maintainability - external/cwe/cwe-584 Query suites: - python-security-and-quality.qls
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.
Either move the
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.