Skip to content

tooling: Enable ruff S110 to detect try-except-pass.#383

Merged
nedseb merged 1 commit intomainfrom
tooling/ruff-s110
Apr 13, 2026
Merged

tooling: Enable ruff S110 to detect try-except-pass.#383
nedseb merged 1 commit intomainfrom
tooling/ruff-s110

Conversation

@nedseb
Copy link
Copy Markdown
Contributor

@nedseb nedseb commented Apr 13, 2026

Closes #384

Problem

Silent try/except: pass patterns 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 S110 rule from flake8-bandit (already part of ruff) which detects try-except-pass:

"S110",   # flake8-bandit: try-except-pass (no silent exception suppression)

Only S110 is enabled (not the full S group), 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: pass found in the codebase:

1. lib/lis2mdl/device.py — unnecessary wrapper around sleep_ms

# Before
try:
    sleep_ms(10)  # Small delay for reset to complete
except Exception:
    pass

# After
sleep_ms(10)  # Small delay for reset to complete

sleep_ms() cannot raise — the try/except was a leftover from older code.

2. tests/report_plugin.py — intentional best-effort fallback

Kept with # noqa: S110 and a clarifying comment. The report plugin must never fail the test session if metadata collection fails.

Test plan

  • ruff check passes
  • 349 mock tests pass

Copilot AI review requested due to automatic review settings April 13, 2026 02:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 S110 to detect try-except-pass.
  • Remove an unnecessary try/except: pass around sleep_ms() in the LIS2MDL driver.
  • Keep an intentional best-effort try/except: pass in 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.

Comment thread tests/report_plugin.py Outdated
Comment on lines 42 to 44
except Exception: # noqa: S110
# Best-effort: report metadata is optional, never fail the test session.
pass
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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 {}

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@nedseb nedseb force-pushed the tooling/ruff-s110 branch from 1b21629 to c50087d Compare April 13, 2026 02:48
@nedseb nedseb merged commit a146427 into main Apr 13, 2026
9 checks passed
@semantic-release-updater
Copy link
Copy Markdown

🎉 This PR is included in version 0.16.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

@nedseb nedseb deleted the tooling/ruff-s110 branch April 16, 2026 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tooling: Enable ruff S110 to detect try-except-pass.

2 participants