Skip to content

chore: narrow or explain every broad except - #202

Merged
petercorke merged 5 commits into
mainfrom
chore/narrow-exceptions
Nov 21, 2026
Merged

petercorke merged 5 commits into
mainfrom
chore/narrow-exceptions

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Summary

Finishes Issue 115 (remaining bare except: and swallowed exceptions), after PR 114, PR 138, PR 140, PR 142, PR 143 and PR 200. Closes #115.

  • Camera.clf now catches only NotImplementedError and ValueError from Artist.remove, and Image.choose only the TypeError and ValueError that getvector raises.
  • Narrowed: _iminteractive.py toolbar check (AttributeError), imtool.py pixel readout (IndexError, which also fixes val being unset for an unknown pixel type), and the optional-import guards in tests/conftest.py (ImportError).
  • Every except Exception that is deliberately broad now has # noqa: BLE001 - reason (GUI event callbacks, self-checks in mvtbtool, the unexpected-failure reporting in Sources.py, the fake ROS server and test cleanup). The three try/except/pass sites in the fake ROS server also carry S110.
  • pyproject.toml: ruff now selects BLE and S110, so new ones are flagged, and excludes the book-code notebooks in tests/RVC (their setup cell has a bare except).

No change to behaviour other than the narrowed handlers. Ruff is not run in CI or pre-commit, so the new rules are enforced only when run locally.

Testing

ruff check --select E722,BLE,S110 src tests passes, mypy passes with zero errors, and the full test suite gives 1466 passed, 41 skipped. Not run: bin/ tools by hand (imtool hover readout, mvtbtool self-check), and the camera plot after Camera.clf on every Matplotlib backend.

This change was written with AI assistance (Claude Code) and the diff has been reviewed by the maintainer.

🤖 Generated with Claude Code

petercorke and others added 4 commits November 22, 2026 06:14
Camera.clf swallowed any error from Artist.remove; only NotImplementedError
(axes furniture) and ValueError (already removed) are expected. Image.choose
now catches the TypeError and ValueError that getvector raises for a bad
color.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Each remaining except Exception is now either narrowed to the exceptions that
can occur or carries a noqa with the reason it is deliberately broad. Enables
BLE in the ruff rules so new ones are flagged. Also fixes imtool's pixel
readout, which left val unset for an unknown pixel type.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@petercorke
petercorke merged commit 54fcb57 into main Nov 21, 2026
34 checks passed
@petercorke
petercorke deleted the chore/narrow-exceptions branch November 21, 2026 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remaining bare except: / swallowed exceptions in tests/ and src/ (Codacy + hidden failures)

1 participant