tooling: Enable ruff S110 to detect try-except-pass.#383
Conversation
There was a problem hiding this comment.
Pull request overview
This PR tightens repository linting by enabling Ruff’s flake8-bandit rule S110, so silent try/except: pass patterns are flagged during CI and don’t slip through review.
Changes:
- Enable Ruff rule
S110to detecttry-except-pass. - Remove an unnecessary
try/except: passaroundsleep_ms()in the LIS2MDL driver. - Keep an intentional best-effort
try/except: passin the pytest report plugin, documented and suppressed with# noqa: S110.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
pyproject.toml |
Adds S110 to Ruff’s lint select list to enforce detection of silent exception suppression. |
lib/lis2mdl/lis2mdl/device.py |
Removes a redundant try/except: pass around a fixed sleep_ms(10) delay during reset. |
tests/report_plugin.py |
Documents and suppresses an intentional best-effort try/except: pass used to avoid failing the test session on metadata collection issues. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| except Exception: # noqa: S110 | ||
| # Best-effort: report metadata is optional, never fail the test session. | ||
| pass |
There was a problem hiding this comment.
The except Exception: ... pass block requires # noqa: S110 and adds a redundant pass before the unconditional return {}. Consider returning {} directly from the except block (and dropping the noqa) to keep the best-effort behavior while avoiding a suppressed try/except/pass pattern.
| except Exception: # noqa: S110 | |
| # Best-effort: report metadata is optional, never fail the test session. | |
| pass | |
| except Exception: | |
| # Best-effort: report metadata is optional, never fail the test session. | |
| return {} |
There was a problem hiding this comment.
Fixed: replaced pass with return {} directly in the except block. The # noqa: S110 is no longer needed since there is no try-except-pass anymore.
1b21629 to
c50087d
Compare
|
🎉 This PR is included in version 0.16.4 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Closes #384
Problem
Silent
try/except: passpatterns hide errors. The github-code-quality bot detected such patterns in PR #382 (deploy_usb.py), but ruff did not catch them automatically — meaning future occurrences would also slip through review.Fix
Enable the
S110rule from flake8-bandit (already part of ruff) which detectstry-except-pass:Only S110 is enabled (not the full
Sgroup), because the other bandit rules (S101 assert, S102 exec, S603/S607 subprocess) produce too many false positives in our test/script code.Existing violations fixed
Two
try-except: passfound in the codebase:1.
lib/lis2mdl/device.py— unnecessary wrapper aroundsleep_mssleep_ms()cannot raise — the try/except was a leftover from older code.2.
tests/report_plugin.py— intentional best-effort fallbackKept with
# noqa: S110and a clarifying comment. The report plugin must never fail the test session if metadata collection fails.Test plan
ruff checkpasses