Skip to content

except-pass (ODW8138)

Deprecated (since 0.16.3.22) · Related issues · View source

Derived from the odoo linter.

Warning: This rule is deprecated and will be removed in a future release.

Deprecation

This rule is deprecated in favor of try-except-pass, which reports the exact same code: an except handler whose whole body is a pass. The rule was ported from pylint-odoo's except-pass before that overlap was noticed, and keeping both meant the same handler was reported twice, once per rule.

What it does

Checks for except blocks whose entire body is a bare pass.

Why is this bad?

Silently swallowing an exception without at least logging it makes bugs hard to diagnose. If the exception is genuinely expected and ignorable, prefer contextlib.suppress, which documents that intent; otherwise, log the exception.

Example

try:
    do_something()
except Exception:
    pass

Use instead:

try:
    do_something()
except Exception:
    _logger.exception("do_something failed")