Ho ho ho! I spent some time to try to resolve the remaining issues with PR 4682. I think everything now works. Returns from a final body of a try/finally was the remaining issue. I've solved it by introducing the POP_NO_EXCEPT opcode. I added a number of comments to help explain to future maintainers what is going on.
The PR still could use some polishing. I have some test cases to add, to trigger the previously buggy try/finally + return case. Also, I think the fblock_unwind_<block type> functions in the compiler could be done more simply. I don't think we need a separate function for each type, just use a case statement on the fblock type. That's a fairly minor detail though.
I would also like to add a bunch more comments. I've spent many hours figuring out how all this stuff works, not that I totally understand everthing. The test case test_contextlib test_exit_exception_with_existing_context() was especially brain-busting. I'm a bit horrified that Python has become so complex to support such things.
Anyhow, I'm off for holidays so no time for further polish until after Christmas. |