Repository navigation
fix(test.py): call _thread.interrupt_main() in pre-imports KBI handlers - #2611
Conversation
Three small linter regressions had master red on every Stop hook run: 1. test.py:50, test.py:59 — KBI002: The pre-imports stdout/stderr reconfigure blocks caught `KeyboardInterrupt` and bare-`raise`'d. PR #2607 silenced this with `# noqa: KBI002`, but the KBI checker's suppression read no longer matches — KBI002 fires every lint run. `_thread` is already imported at the top of the file, so calling `_thread.interrupt_main()` before the re-raise is a one-line fix that satisfies the checker's "must notify the main thread" rule without any additional imports (handle_keyboard_interrupt isn't available yet at this pre-import point in startup). 2. test.py:779 — ruff warning "Invalid rule code provided to # noqa: KBI002": Ruff doesn't know about the custom KBI* codes from ci/lint_python/keyboard_interrupt_checker.py, so it rejects `# noqa: KBI002` even though our KBI checker honors it. Fix: register `KBI001`, `KBI002`, `KBI003` in `[tool.ruff.lint] external` (same mechanism already used for DCT001/DCT002). The line-779 handler legitimately wants to swallow the KBI rather than re-raise (top-level safety net, uses `sys.exit(1)` to avoid leaking KBI to parent processes), so suppression is the right answer there. 3. ci/lint_python/keyboard_interrupt_checker.py:79 — ruff warning "Invalid `# noqa` directive": The literal text ``# noqa`` in a code comment ("bare ``# noqa`` suppresses everything") was being parsed by ruff's noqa-directive detector. Reword to "bare ``noqa`` (no codes) suppresses everything" so ruff stops seeing it as a directive site. All three changes are tiny and behavior-preserving. After this: $ bash lint 🎉 All linting completed!
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe PR introduces infrastructure for custom KeyboardInterrupt checker codes (KBI001–KBI003) to enforce consistent interrupt handling patterns. It registers these codes in Ruff's linter configuration and applies them by invoking ChangesKeyboardInterrupt Handling Infrastructure
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Three small linter regressions had master red on every Stop hook run. All three fixes are tiny and behavior-preserving.
1.
test.py:50,test.py:59— KBI002The pre-imports stdout/stderr
reconfigureblocks caughtKeyboardInterruptand bare-raise'd. PR #2607 silenced this with# noqa: KBI002, but the custom KBI checker's suppression read no longer matches — KBI002 fires every lint run._threadis already imported at the top oftest.py, so calling_thread.interrupt_main()before the re-raise is a one-line fix that satisfies the checker's "must notify the main thread" rule.handle_keyboard_interruptisn't available yet at this pre-import startup point, so the lower-level_thread.interrupt_main()is the right call here.2.
test.py:779— ruff "Invalid rule code provided to # noqa: KBI002"Ruff doesn't know about the custom KBI* codes from
ci/lint_python/keyboard_interrupt_checker.py, so it rejects# noqa: KBI002even though our KBI checker honors it.Fix: register
KBI001,KBI002,KBI003in[tool.ruff.lint] external(same mechanism already used forDCT001/DCT002). The line-779 handler legitimately wants to swallow the KBI rather than re-raise (top-level safety net, usessys.exit(1)to avoid leaking KBI to parent processes), so suppression is the right answer there.3.
ci/lint_python/keyboard_interrupt_checker.py:79— ruff "Invalid# noqadirective"The literal text
# noqainside an English-language comment ("bare \`# noqa`` suppresses everything") was being parsed by ruff's noqa-directive detector. Reword to"bare ``noqa`` (no codes) suppresses everything"` so ruff stops seeing it as a directive site.Test plan
bash lint— clean (🎉 All linting completed!, no warnings)uv run python -m ci.lint_python.keyboard_interrupt_checker test.py— silentuv run ruff check test.py—All checks passed!🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Chores