Skip to content

fix(test.py): suppress KBI002 on pre-imports reconfigure blocks - #2607

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

zackees merged 1 commit into
masterfrom
fix/test-py-kbi002-startup

Conversation

@zackees

@zackees zackees commented May 30, 2026 •

Copy link
Copy Markdown
Member

Summary

The stop-hook lint flagged two KBI002 violations at `test.py:50` and `:59` — the `except KeyboardInterrupt: raise` blocks I added in #2587 for CodeRabbit don't satisfy the KBI checker (which wants `_thread.interrupt_main()` or `handle_keyboard_interrupt(ki)`).

The honest answer is `# noqa: KBI002` with an explanatory comment: those two blocks run before `from ci.util.global_interrupt_handler import handle_keyboard_interrupt` at line 80, so the helper isn't available yet. Inlining `import _thread; _thread.interrupt_main()` would also re-schedule the same interrupt we're already handling on the main thread — a no-op that just adds clutter. The bare re-raise is correct for this microsecond-wide startup window.

Test plan

  • `bash lint` clean (was failing on these two lines before)
  • CI: `unit tests linux` etc. unchanged (test.py path unaffected)

Summary by CodeRabbit

  • Chores
    • Updated code quality compliance in test configuration files.

No user-facing changes.

Review Change Stack

PR #2587 added `except KeyboardInterrupt: raise` to the two
sys.stdout/stderr.reconfigure blocks at the very top of test.py to
satisfy CodeRabbit's "catch KeyboardInterrupt before ValueError" ask.
The KBI002 checker then flagged those bare `raise`s because the
handler doesn't call _thread.interrupt_main() or
handle_keyboard_interrupt(ki).

The honest fix is `# noqa: KBI002`: these blocks run BEFORE
`from ci.util.global_interrupt_handler import handle_keyboard_interrupt`
at line 80. The helper isn't available yet. Inlining
`import _thread; _thread.interrupt_main()` here would also re-schedule
the same interrupt we're already handling on the main thread (no-op,
adds clutter). The bare re-raise is correct for this microsecond-wide
startup window; the noqa with explanatory comment documents why.
@zackees
zackees merged commit 83a7ea1 into master May 30, 2026
1 of 3 checks passed
@zackees
zackees deleted the fix/test-py-kbi002-startup branch May 30, 2026 19:57
@coderabbitai

coderabbitai Bot commented May 30, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 41f500ad-ffa9-4b11-8091-fe6765e613f1

📥 Commits

Reviewing files that changed from the base of the PR and between 7fd161e and 177d786.

📒 Files selected for processing (1)
  • test.py

📝 Walkthrough

Walkthrough

Linting annotations and comments are added to KeyboardInterrupt exception handlers in test.py's stdout and stderr line-buffering reconfiguration blocks to suppress KBI002 warnings and clarify import timing context.

Changes

Line-buffering reconfiguration linting

Layer / File(s) Summary
KeyboardInterrupt handler linting annotations
test.py
# noqa: KBI002 annotations suppress linting warnings on KeyboardInterrupt handlers in stdout and stderr reconfigure(line_buffering=True) blocks; comments clarify helper availability and import timing.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • FastLED/FastLED#2544: Both PRs modify test.py's stdout/stderr line-buffering reconfigure blocks (the retrieved PR changes how reconfigure is invoked safely, while this PR tweaks the exception/annotation handling in the same reconfiguration sections).
  • FastLED/FastLED#2587: Both PRs modify test.py's stdout/stderr line-buffering reconfigure try/except blocks to adjust KeyboardInterrupt handling in the same locations.
  • FastLED/FastLED#2550: Both PRs adjust except KeyboardInterrupt handling to satisfy KBI002 linting rules through annotations and comments in test.py.

Poem

A linter's squeak, a whisker's twitch,
We silence warnings with # noqa stitch,
KeyboardInterrupt, now at peace,
Comments clarify—bugs will cease! 🐰✨

✨ 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-kbi002-startup

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 added a commit that referenced this pull request May 30, 2026
…rs (#2611)

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