Skip to content

Commit 07e8d85

Browse files
committed
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.
1 parent b3dfeba commit 07e8d85

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

lib/galaxy/managers/sse_dispatch.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from typing import (
1616
Any,
1717
Optional,
18+
Protocol,
1819
)
1920

2021
from cachetools import TTLCache
@@ -29,6 +30,17 @@
2930
from galaxy.web.statsd_client import VanillaGalaxyStatsdClient
3031
from galaxy.web_stack import ApplicationStack
3132

33+
34+
class ControlTaskLike(Protocol):
35+
"""Structural type for the dispatcher's control-task collaborator.
36+
37+
The dispatcher only calls ``send_task(**kwargs)``. Typed as a Protocol so
38+
tests can pass lightweight fakes (``FakeControlTask``, ``NoopControlTask``)
39+
without subclassing ``ControlTask``.
40+
"""
41+
42+
def send_task(self, **kwargs: Any) -> Any: ...
43+
3244
log = logging.getLogger(__name__)
3345

3446

@@ -56,7 +68,7 @@ def __init__(
5668
application_stack: ApplicationStack,
5769
statsd_client: Optional[VanillaGalaxyStatsdClient] = None,
5870
clock: Callable[[], float] = time.monotonic,
59-
control_task_factory: Callable[[GalaxyQueueWorker], ControlTask] = ControlTask,
71+
control_task_factory: Callable[[GalaxyQueueWorker], ControlTaskLike] = ControlTask,
6072
queues_provider: Optional[Callable[[], list[Queue]]] = None,
6173
) -> None:
6274
self._queue_worker = queue_worker

lib/galaxy_test/base/sse.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99

1010
import queue
1111
import threading
12-
from typing import (
13-
Callable,
14-
Optional,
15-
)
12+
from collections.abc import Callable
13+
from typing import Optional
1614

1715
import requests
1816

0 commit comments

Comments
 (0)