PEP 8: Discourage use of return/break/continue in finally (#1174)

This commit is contained in:
Damien George 2019-09-24 00:14:57 +10:00 committed by Guido van Rossum
parent 8400ea55ac
commit 2ce88849fd
1 changed files with 14 additions and 0 deletions

View File

@ -1335,6 +1335,20 @@ Programming Recommendations
No: if greeting == True:
Worse: if greeting is True:
- Use of the flow control statements ``return``/``break``/``continue``
within the finally suite of a ``try...finally``, where the flow control
statement would jump outside the finally suite, is discouraged. This
is because such statements will implicitly cancel any active exception
that is propagating through the finally suite.
No::
def foo():
try:
1 / 0
finally:
return 42
Function Annotations
--------------------