-
Notifications
You must be signed in to change notification settings - Fork 1
Closed
Labels
awCreated by agentic workflowCreated by agentic workflowcode-healthCode cleanup and maintenanceCode cleanup and maintenance
Description
Root Cause
_FileChangeHandler in cli.py (lines 117–128) relies on duck typing instead of inheriting from watchdog.events.FileSystemEventHandler:
class _FileChangeHandler:
"""Watchdog handler that triggers refresh on any session-state change."""
def __init__(self, change_event: threading.Event) -> None:
self._change_event = change_event
self._last_trigger = 0.0
def dispatch(self, event: object) -> None: # noqa: ANN001
...Two suppressions result from this:
-
# noqa: ANN001ondispatch— the event parameter can't be typed without importing watchdog event types, so the annotation is omitted and the linter warning suppressed. -
# type: ignore[arg-type]onobserver.schedule(handler, ...)— becausehandleris not a recognisedFileSystemEventHandlersubtype from the static analysis perspective.
Observer.schedule expects a FileSystemEventHandler instance. The duck-typing approach works today, but it:
- Loses the
BaseEventHandler/FileSystemEventHandlerlifecycle hooks (e.g.on_any_event) that watchdog may start calling in future versions - Obscures intent — a reader must know that watchdog uses duck typing to understand why
dispatchis defined here - Carries two
noqa/type: ignoresuppressions that mask any future type regressions
Fix
from watchdog.events import FileSystemEventHandler # type: ignore[import-untyped]
class _FileChangeHandler(FileSystemEventHandler): # type: ignore[misc]
"""Watchdog handler that triggers refresh on any session-state change."""
def __init__(self, change_event: threading.Event) -> None:
super().__init__()
self._change_event = change_event
self._last_trigger = 0.0
def dispatch(self, event: object) -> None:
now = time.monotonic()
if now - self._last_trigger > 2.0:
self._last_trigger = now
self._change_event.set()- Remove
# noqa: ANN001fromdispatch - Remove
# type: ignore[arg-type]fromobserver.schedule(...) - Add
super().__init__()call - The
# type: ignore[misc]on the class line coversFileSystemEventHandlerbeing from an untyped package (same pattern already used for Observer)
Acceptance Criteria
-
_FileChangeHandlerinherits fromwatchdog.events.FileSystemEventHandler -
super().__init__()called in__init__ -
# noqa: ANN001removed fromdispatch -
# type: ignore[arg-type]removed fromobserver.schedule(...) - All existing tests pass
- New test: instantiate
_FileChangeHandler, calldispatch(object()), assertchange_eventis set (covers the inheritance path at runtime, not just the constructor)
Generated by Code Health Analysis · ◷
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
awCreated by agentic workflowCreated by agentic workflowcode-healthCode cleanup and maintenanceCode cleanup and maintenance