Fix CI: Callable import + ControlTaskLike Protocol

Two failures introduced by the previous polish commits caught by CI:

- ruff UP035 on lib/galaxy_test/base/sse.py: Callable must be imported
  from collections.abc, not typing (newer ruff version than the local
  venv had).

- packages mypy on test_sse_dispatch_cache.py:78: the injected
  control_task_factory's type was Callable[[GalaxyQueueWorker],
  ControlTask], which rejected NoopControlTask (and would have also
  rejected FakeControlTask / BoomControlTask) because none of the test
  classes subclass ControlTask.

Introduce a ControlTaskLike Protocol covering the single method the
dispatcher calls (``send_task(**kwargs)``) and type the factory against
it. Keeps ControlTask itself as the production default and lets the
test fakes pass via structural typing.
This commit is contained in:
mvdbeek
2026-04-28 17:20:23 +02:00
parent 78ab002ba4
commit b3b75b59cf
2 changed files with 15 additions and 5 deletions
+13 -1
View File
@@ -15,6 +15,7 @@ from collections.abc import Callable
from typing import (
Any,
Optional,
Protocol,
)
from cachetools import TTLCache
@@ -29,6 +30,17 @@ from galaxy.queues import all_control_queues_for_declare
from galaxy.web.statsd_client import VanillaGalaxyStatsdClient
from galaxy.web_stack import ApplicationStack
class ControlTaskLike(Protocol):
"""Structural type for the dispatcher's control-task collaborator.
The dispatcher only calls ``send_task(**kwargs)``. Typed as a Protocol so
tests can pass lightweight fakes (``FakeControlTask``, ``NoopControlTask``)
without subclassing ``ControlTask``.
"""
def send_task(self, **kwargs: Any) -> Any: ...
log = logging.getLogger(__name__)
@@ -56,7 +68,7 @@ class SSEEventDispatcher:
application_stack: ApplicationStack,
statsd_client: Optional[VanillaGalaxyStatsdClient] = None,
clock: Callable[[], float] = time.monotonic,
control_task_factory: Callable[[GalaxyQueueWorker], ControlTask] = ControlTask,
control_task_factory: Callable[[GalaxyQueueWorker], ControlTaskLike] = ControlTask,
queues_provider: Optional[Callable[[], list[Queue]]] = None,
) -> None:
self._queue_worker = queue_worker
+2 -4
View File
@@ -9,10 +9,8 @@ thread instead of silently swallowing them.
import queue
import threading
from typing import (
Callable,
Optional,
)
from collections.abc import Callable
from typing import Optional
import requests