Context Managers as a Pattern
Context managers guarantee setup and teardown around a block of code. The with statement calls __enter__/__exit__ (or @contextmanager yield) so resources release even when exceptions fire - files close, locks release, and transactions roll back.