Created
June 8, 2025 19:06
-
-
Save sobolevn/92e94c132b0ba7834e5f2e2ec39fda83 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> def other(x, y): | |
... res = None | |
... try: | |
... res = x / y | |
... except ZeroDivisionError: | |
... res = 0 | |
... finally: | |
... print(res) | |
... | |
>>> import dis | |
>>> dis.dis(other) | |
1 RESUME 0 | |
2 LOAD_CONST 0 (None) | |
STORE_FAST 2 (res) | |
3 NOP | |
4 L1: LOAD_FAST_BORROW_LOAD_FAST_BORROW 1 (x, y) | |
BINARY_OP 11 (/) | |
STORE_FAST 2 (res) | |
8 L2: LOAD_GLOBAL 3 (print + NULL) | |
LOAD_FAST_BORROW 2 (res) | |
CALL 1 | |
POP_TOP | |
LOAD_CONST 0 (None) | |
RETURN_VALUE | |
-- L3: PUSH_EXC_INFO | |
5 LOAD_GLOBAL 0 (ZeroDivisionError) | |
CHECK_EXC_MATCH | |
POP_JUMP_IF_FALSE 6 (to L5) | |
NOT_TAKEN | |
POP_TOP | |
6 LOAD_SMALL_INT 0 | |
STORE_FAST 2 (res) | |
L4: POP_EXCEPT | |
JUMP_BACKWARD_NO_INTERRUPT 28 (to L2) | |
5 L5: RERAISE 0 | |
-- L6: COPY 3 | |
POP_EXCEPT | |
RERAISE 1 | |
L7: PUSH_EXC_INFO | |
8 LOAD_GLOBAL 3 (print + NULL) | |
LOAD_FAST 2 (res) | |
CALL 1 | |
POP_TOP | |
RERAISE 0 | |
-- L8: COPY 3 | |
POP_EXCEPT | |
RERAISE 1 | |
ExceptionTable: | |
L1 to L2 -> L3 [0] | |
L3 to L4 -> L6 [1] lasti | |
L4 to L5 -> L7 [0] | |
L5 to L6 -> L6 [1] lasti | |
L6 to L7 -> L7 [0] | |
L7 to L8 -> L8 [1] lasti |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment