refactor: dedupe silent exception cleanup in hotkey service and main app - #62
Merged
Merged
Conversation
- hotkey_service: reuse _close_devices() for the two fallback-candidate close loops in _discover_keyboards instead of repeating try/except/pass. - blitztext_linux: centralize the identical cosmetic window-icon try/except in _apply_window_icon() for the compose and main windows. Behavior is unchanged. BLE001 35 -> 29 and S110 10 -> 7 in app/, repo-wide ruff 287 -> 281; pytest 684 passed before and after. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed?
Two behavior-preserving deduplications of silent exception handling (2 files, +12/-18):
app/hotkey_service.py: the two hand-written fallback-candidate close loops in_discover_keyboardsnow call the existing_close_devices()helper (_close_devices(fallback_candidates)and_close_devices(fallback_candidates[1:])). The helper does exactly the same: iterate over alist()copy,dev.close(), ignore errors.app/blitztext_linux.py: the two identical cosmetictry: window.setWindowIcon(theme.create_app_icon()) / except Exception: passblocks in_ensure_compose_windowand_ensure_main_windoware centralized in a module-level_apply_window_icon(window)(keeps# pragma: no cover; comment now in English).Why?
Follow-up to #61 from the same cleanup audit: removes duplicated blind/silent handlers without changing what they catch or when. Nothing else from the audit is included on purpose (no narrowing of exception types, no logging).
Note: the icon helper contains one handler itself, so item 2 nets -1 (not -2) per rule; item 1 nets -2 per rule.
How did you test it?
Baseline on
main(5fbe28d) vs. this branch (be4d8d3).Tests (
QT_QPA_PLATFORM=offscreen WHISPER_GUI_TESTS=1 XDG_RUNTIME_DIR=/run/user/1000):pytest tests/Ruff (0.16.8,
--no-cache, default rules for the repo-wide count;--select BLE001,S110 app/for the rule counts):ruff check .)app/The per-rule statistics differ only in BLE001 and S110; every other rule count is identical.
git diff --checkis clean.Real Wayland GUI smoke test (native
waylandsession, isolated tempHOME, hotkey worker disabled so it does not compete with the running user service; same script run against an export ofmainand against this branch):show_*call reuses the same window objectssys.excepthookhits, stderr_discover_keyboards()against real/dev/input(read-only, no grab): returned devicesevdevclose()calls (during discovery / total)theme.create_app_iconraisingRuntimeError: Compose window still constructedRendered screenshots of both windows were inspected and look correct.
Limits: the hotkey worker was disabled in the smoke test, so the new
_close_devicescalls were exercised through_discover_keyboards()with real devices, not through a live listener. The icon paths have no unit tests (create_app_iconis not mocked intests/).Rollback:
git revert <squash commit>.AI assistance
Yes. Implemented and verified with Claude Code (Claude Sonnet 5) from an exception-handler audit; the diff was reviewed by the maintainer before committing.
Checklist
pytest tests/(offscreen) or explained why not.🤖 Generated with Claude Code