Skip to content

fix(test.py): call _thread.interrupt_main() in pre-imports KBI handlers - #2611

Merged
zackees merged 1 commit into
masterfrom
fix/test-py-kbi-handlers
May 30, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/test-py-kbi-handlers

Conversation

@zackees

@zackees zackees commented May 30, 2026 •

Copy link
Copy Markdown
Member

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 — KBI002

The pre-imports stdout/stderr reconfigure blocks caught KeyboardInterrupt and 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.

_thread is already imported at the top of test.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_interrupt isn'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: 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 "Invalid # noqa directive"

The literal text # noqa inside 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)
  • KBI checker direct: uv run python -m ci.lint_python.keyboard_interrupt_checker test.py — silent
  • uv run ruff check test.py — All checks passed!

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced keyboard interrupt handling during startup configuration to ensure proper signal propagation.
  • Chores

    • Extended linting configuration with support for additional custom checker codes.
    • Updated documentation in code validation tools.

Review Change Stack

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!
@coderabbitai

coderabbitai Bot commented May 30, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: cebeec18-0223-4ff6-9d0e-ba06987f8715

📥 Commits

Reviewing files that changed from the base of the PR and between 2461b7d and 425614d.

📒 Files selected for processing (3)
  • ci/lint_python/keyboard_interrupt_checker.py
  • pyproject.toml
  • test.py

📝 Walkthrough

Walkthrough

The 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 _thread.interrupt_main() in test startup's stdout/stderr reconfiguration paths before re-raising the interrupt.

Changes

KeyboardInterrupt Handling Infrastructure

Layer / File(s) Summary
KBI codes registration and checker clarification
ci/lint_python/keyboard_interrupt_checker.py, pyproject.toml
Ruff's external noqa codes are extended to register KBI001, KBI002, and KBI003. The keyboard interrupt checker helper's inline comment is clarified for the bare noqa suppression case.
KeyboardInterrupt propagation in startup stdout/stderr reconfigure
test.py
Both stdout and stderr reconfigure(line_buffering=True) paths now handle KeyboardInterrupt by invoking _thread.interrupt_main() before re-raising, replacing the prior bare re-raise behavior to ensure consistent interrupt signal flow.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • FastLED/FastLED#2586: Explicitly re-raises KeyboardInterrupt in ci/wasm_build.py to avoid swallowing it, aligning with the interrupt propagation pattern.
  • FastLED/FastLED#2544: Modifies the same test.py stdout/stderr reconfigure(line_buffering=True) paths with reworked exception handling.
  • FastLED/FastLED#2587: Updates the same test.py KeyboardInterrupt handling flow in the reconfigure blocks.

Poem

🐰 Interrupt signals now flow clear,
Through startup's buffering frontier,
With KBI codes to light the way,
Keyboard handlers save the day! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the primary change: fixing test.py to call _thread.interrupt_main() in KeyboardInterrupt handlers during pre-imports.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/test-py-kbi-handlers

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@zackees
zackees merged commit b9d954e into master May 30, 2026
7 of 8 checks passed
@zackees
zackees deleted the fix/test-py-kbi-handlers branch August 21, 2026 19:16
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.

1 participant