Skip to content
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

Implement Python 3.8 && 3.9 try-except-finally logic #493

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Levak
Copy link
Contributor

@Levak Levak commented Jun 24, 2024

  • Add tests for simple cases of try-except-finally (rename one old Python 2.6 test);

  • Implement JUMP_IF_NOT_EXC_MATCH_A with a fake CMP_EXCEPTION followed by a POP_JUMP_IF_TRUE;

  • Implement BEGIN_FINALLY with a fake LOAD_CONST_A None;

  • Implement Python 3.8+ specific SETUP_FINALLY_A handling both EXCEPT and FINALLY cases. We guess which is which by looking at the targeted block that seems to either be a POP_TOP or a DUP_TOP in the case of an EXCEPT block;

  • Implement RERAISE with a fake END_FINALLY;

  • In Python 3.9+, emulate a BEGIN_FINALLY when POP_BLOCK is not followed by a JUMP_FORWARD_A (maybe source of bugs);

  • In Python 3.9+, skip the duplicated code from the FINALLY blocks with a jump in bytecode and a fake END_FINALLY.

- Add tests for simple cases of try-except-finally;

- Implement `JUMP_IF_NOT_EXC_MATCH_A` with a fake `CMP_EXCEPTION`
  followed by a `POP_JUMP_IF_TRUE`;

- Implement `BEGIN_FINALLY` with a fake `LOAD_CONST_A None`;

- Implement Python 3.8+ specific `SETUP_FINALLY_A` handling both
  EXCEPT and FINALLY cases. We guess which is which by looking
  at the targetted block that seems to either be a POP_TOP or a
  DUP_TOP in the case of an EXCEPT block;

- Implement RERAISE with a fake END_FINALLY;

- In Python 3.9+, skip the duplicated code from the FINALLY blocks
  with a jump in bytecode and a fake `END_FINALLY`.
@EchoStretch
Copy link

Fantastic update! I think this one works the best so far. There are still a few I'm not able to resolve, but I'm reviewing everyone’s repos to get more insights.

Unsupported opcode: LOAD_ASSERTION_ERROR
Unsupported opcode: LOAD_ASSERTION_ERROR
Unsupported opcode: LOAD_ASSERTION_ERROR
Warning: Stack history is not empty!
Warning: block stack is not empty!
Warning: block stack is not empty!
Warning: block stack is not empty!
Warning: Stack history is not empty!
Warning: block stack is not empty!
Unsupported opcode: LOAD_ASSERTION_ERROR
Unsupported opcode: LOAD_ASSERTION_ERROR
Warning: block stack is not empty!
Unsupported opcode: LOAD_ASSERTION_ERROR
Unsupported opcode: LOAD_ASSERTION_ERROR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants