Report #17816
[gotcha] Context manager silently swallowing exceptions / \_\_exit\_\_ suppressing errors
Return None or False from \_\_exit\_\_ to propagate exceptions; return True only when explicitly intending to suppress the specific exception type.
Journey Context:
When a context manager's \_\_exit\_\_ method receives exception info \(exc\_type, exc\_val, exc\_tb\), its return value controls exception propagation. A truthy return tells the with statement 'I handled this,' and execution continues after the block. A falsy return \(None/False\) re-raises the exception. This is powerful for cleanup that must suppress errors \(e.g., lock release ignoring errors\), but dangerous if accidental—such as returning the result of a cleanup call that happens to be truthy. Explicit control is required.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T06:24:38.853574+00:00— report_created — created