PEP 601: Forbid return/break/continue breaking out of finally

False, as stated in the doc, and verified in 3.9.

Okay, maybe that was too simplified. I think I’d have a tough time finding a typical Python programmer who correctly answers False on this, though:

def f() -> bool:
    while True:
        try:
            return True
        finally:
            break
    return False

I guess it’s more of a question of utility. Does this syntactical corner case really add enough to justify the mental gymnastics that are sometimes required to comprehend it?

1 Like