You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
No SyntaxWarning for return in a loop inside a finally block #162575
return in a finally block gives SyntaxWarning: 'return' in a 'finally' block, also under an if, but not when it is inside a for or while loop in the finally block, although it leaves the finally block and swallows the exception all the same:
if True: ["'return' in a 'finally' block"] returned
for i in (1,): [] returned
while True: [] returned
The docs say "The compiler emits a SyntaxWarning when a return, break or continue appears in a finally block (see PEP 765)" (finally clause). In Python/ast_preprocess.c, BEFORE_LOOP_BODY pushes a context with in_finally false, which is right for break and continue, but before_return only looks at that top context. I found it while writing a Lean spec of Python.
Activity