Skip to content

bpo-37830: Revert "bpo-32489: Allow 'continue' in 'finally' clause. (GH-5822)" #15230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Aug 12, 2019

@isidentical
Copy link
Member

Then i am closing #15221

@pablogsal
Copy link
Member

We should also inform @ambv so it removes this from the main announcement of future releases.

@dpgeorge
Copy link

FWIW I think that continue should never be allowed in a finally clause because it's tricky to implement, and simply should not be used in scripts (I feel the same about break and return in a finally, but that's not really possible to ban at this point). We had similar VM seg-faults in MicroPython for all these "unwinding jumps", see micropython/micropython@b735208 and micropython/micropython@e1fb03f for the fixes (for return and break respectively). Banning this syntax at the compile level would make things simpler.

@ncoghlan FYI we did discuss this topic at PyCon AU 2018

@serhiy-storchaka
Copy link
Member Author

Actually this reversion does not solve the issue completely: https://bugs.python.org/issue37830#msg349513. So it does not make sense to do it.

@ncoghlan
Copy link
Contributor

The rationale of making life easier for interpreter implementors still applies though - the fact that try/finally can be used to suppress an exception is genuinely weird.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I'm ok to revert the change in Python 3.8 to get more time to find maybe a different approach in Python 3.9. Right now, we have to focus on stabilizing Python 3.8.

@serhiy-storchaka
Copy link
Member Author

I have closed this issue because I do not see any sense in reverting changes for continue if there is the same issue with break. At least continue is not used in existing code, so it will not crash any program.

@ncoghlan
Copy link
Contributor

@serhiy-storchaka The request from MicroPython was to reconsider allowing this construct at all. The fact that break is broken in the same way is a solid argument that we should stop digging the hole deeper (and perhaps consider disallowing break as well). We're making work for other implementations for no good reason.

@ncoghlan ncoghlan reopened this Aug 14, 2019
@dpgeorge
Copy link

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.

@ncoghlan
Copy link
Contributor

@isidentical @dpgeorge A draft PEP for that would be a good next step. I'd be happy to take on the PEP sponsor role.

For continue, the proposal would be to not add support in Python 3.8, while for return and break, the proposal would be to deprecate in 3.9, emit a compilation warning in 3.10, and then disallow after that.

@dpgeorge
Copy link

Ok, I'll draft a PEP.

@serhiy-storchaka
Copy link
Member Author

PEP 601 was rejected (although I think it contains a reasonable seed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting merge DO-NOT-MERGE type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants