◐ Shell
clean mode source ↗

bpo-37830: Revert "bpo-32489: Allow 'continue' in 'finally' clause. (GH-5822)" by serhiy-storchaka · Pull Request #15230 · python/cpython

The request from MicroPython was to reconsider allowing this construct at all.

Probably here is not the right place to have such a discussion, but my aim was to raise the point that we also had issues with return/break/continue in a finally, and that I would support changing the language to disallow this combination of constructs.

return/break/continue in a finally suite will (silently) cancel any raised exception, which is unexpected behaviour and probably not what the writer of the Python code intended. At least there are other ways to write such code (without having return/break/continue in the finally) which has more explicit behaviour. I did a survey of the Python standard library and this pattern is rarely used. And where it is used it's easy to change it.

I would consider writing a PEP to disallow this construct, if there's interest.