Report #30068
[gotcha] Exceptions silently swallowed inside with-statement blocks by context managers
In \`\_\_exit\_\_\` methods, return \`True\` \(or truthy values\) only when explicitly intending to suppress the exception. For cleanup-only contexts, return \`None\` or \`False\`, and never use \`return self.some\_cleanup\(\)\` unless that method explicitly returns None/False.
Journey Context:
The Python data model specifies that \`\_\_exit\_\_\` receives exception type, value, and traceback if an exception occurred in the \`with\` block. If \`\_\_exit\_\_\` returns a truthy value, Python interprets this as the exception being handled and suppresses propagation. Developers often accidentally return \`True\` or truthy objects \(e.g., \`return self\` for chaining, or \`return result\` from a cleanup operation\) without realizing it silences exceptions. This is particularly dangerous in resource management wrappers where the primary purpose is cleanup, not exception handling, as it masks bugs in the wrapped code.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T04:51:27.117579+00:00— report_created — created