MCPcopy Index your code
hub / github.com/python/mypy / transform_try_finally_stmt

Function transform_try_finally_stmt

mypyc/irbuild/statement.py:892–926  ·  view source on GitHub ↗

Generalized try/finally handling that takes functions to gen the bodies. The point of this is to also be able to support with.

(
    builder: IRBuilder, try_body: GenFunc, finally_body: GenFunc, line: int = -1
)

Source from the content-addressed store, hash-verified

890
891
892def transform_try_finally_stmt(
893 builder: IRBuilder, try_body: GenFunc, finally_body: GenFunc, line: int = -1
894) -> None:
895 """Generalized try/finally handling that takes functions to gen the bodies.
896
897 The point of this is to also be able to support with."""
898 # Finally is a big pain, because there are so many ways that
899 # exits can occur. We emit 10+ basic blocks for every finally!
900
901 err_handler, main_entry, return_entry, finally_block = (
902 BasicBlock(),
903 BasicBlock(),
904 BasicBlock(),
905 BasicBlock(),
906 )
907
908 # Compile the body of the try
909 ret_reg = try_finally_try(builder, err_handler, return_entry, main_entry, try_body)
910
911 # Set up the entry blocks for the finally statement
912 old_exc = try_finally_entry_blocks(
913 builder, err_handler, return_entry, main_entry, finally_block, ret_reg
914 )
915
916 # Compile the body of the finally
917 cleanup_block, finally_control = try_finally_body(
918 builder, finally_block, finally_body, old_exc
919 )
920
921 # Resolve the control flow out of the finally block
922 out_block = try_finally_resolve_control(
923 builder, cleanup_block, finally_control, old_exc, ret_reg
924 )
925
926 builder.activate_block(out_block)
927
928
929def transform_try_finally_stmt_async(

Callers 2

transform_try_stmtFunction · 0.85
transform_withFunction · 0.85

Calls 6

BasicBlockClass · 0.90
try_finally_tryFunction · 0.85
try_finally_entry_blocksFunction · 0.85
try_finally_bodyFunction · 0.85
activate_blockMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…