How With Statements Compile

May 30, 2026 | 5 min read

Enter

__enter__ is called and the result is bound.

Body

The with body compiles normally.

Exit

__exit__ is called on both normal and exception paths.

Nested With

Multiple context managers compile to sequential enter/exit blocks.