Typed callback protocols for notify_callback and ops_alert_fn#66
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughTwo new ChangesCallback Protocol Typing
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai full review |
✅ Action performedFull review finished. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
.pre-commit-config.yaml (1)
25-26: ⚡ Quick winInclude
src/paperscout/__main__.pyin the mypy hook target list.The callback is wired at the
Scheduler(...)call site insrc/paperscout/__main__.py; excluding it means pre-commit won’t catch signature drift there.Suggested diff
- args: [src/paperscout/protocols.py, src/paperscout/monitor.py] + args: [src/paperscout/protocols.py, src/paperscout/monitor.py, src/paperscout/__main__.py]🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.pre-commit-config.yaml around lines 25 - 26, The mypy hook configuration in the pre-commit args list is missing the __main__ module from its target files. Currently the args array only includes the protocols and monitor modules. Add the __main__ module to the args list in the mypy hook configuration so that mypy will validate the Scheduler call site and catch any signature drift there.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In @.pre-commit-config.yaml:
- Around line 25-26: The mypy hook configuration in the pre-commit args list is
missing the __main__ module from its target files. Currently the args array only
includes the protocols and monitor modules. Add the __main__ module to the args
list in the mypy hook configuration so that mypy will validate the Scheduler
call site and catch any signature drift there.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: fbb276a0-cf21-40f1-800d-6dd44250ce45
📒 Files selected for processing (7)
.pre-commit-config.yamlpyproject.tomlsrc/paperscout/__main__.pysrc/paperscout/monitor.pysrc/paperscout/protocols.pytests/test_callback_protocols.pytests/typing/invalid_callbacks.py
Summary
Replace bare / partially-typed callback parameters in
Schedulerwith explicittyping.Protocolclasses. A caller that passes a function with the wrong signature is now caught by the type checker at author time rather than at runtime.Changes
protocols.py: Add@runtime_checkableNotifyCallback((PollResult) -> None) andOpsAlertFn((str) -> None);PollResultimported underTYPE_CHECKINGto avoid circular import.monitor.py:notify_callbackandops_alert_fnparams and instance attributes annotated with the new Protocol types; unusedCallableimport removed.__main__.py:_on_poll_resultclosure gains explicitresult: PollResultannotation; structurally satisfiesNotifyCallback.pyproject.toml: Per-modulestrict = trueoverride forpaperscout.protocolsandpaperscout.monitor;typing/added to pytestnorecursedirs..pre-commit-config.yaml: Localuv run mypyhook forprotocols.py+monitor.py(uses project's ownuv.lockmypy, avoids version drift).tests/test_callback_protocols.py— isinstance conformance, scheduler wiring, and subprocess mypy negative test;tests/typing/invalid_callbacks.pyholds deliberate type errors verified by that test.Acceptance criteria
NotifyCallbackandOpsAlertFnProtocol classes definedmonitor.pyannotated--strictpasses onprotocols.py+monitor.pytest_mypy_rejects_invalid_callbacks)Test plan
uv run pytest tests/— 369 passed, 2 skippeduv run mypy src/paperscout/protocols.py src/paperscout/monitor.py— clean (strict)uv run mypy tests/typing/invalid_callbacks.py— 2[assignment]errors as expecteduv run pre-commit run --all-files— all hooks passedRelated
Summary by CodeRabbit