question 322 Decorators & Context Managers · hard
The transaction that hides its failures
transaction(ledger) should make a block of edits to a list of ledger entries all-or-nothing: on an error, the ledger goes back exactly to how it was and the error reaches the caller. Two bugs: callers never see the errors, and after a failed block some entries still have the new amounts. Fix both.
Context manager
transaction(ledger) from @contextmanager; yields the ledger (a list of entry dictionaries)On errorthe ledger has the same entries with the same values as before; the exception propagates
On successthe edits stay