Skip to content

Commit 5dc4ba3

Browse files
committed
Fix mypy typing confusion over CommonTransport factories
1 parent 8f5af19 commit 5dc4ba3

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/workflows/contrib/start_service.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from __future__ import annotations
22

33
import sys
4+
from collections.abc import Callable
45
from optparse import SUPPRESS_HELP, OptionParser
56

67
import workflows
78
import workflows.frontend
89
import workflows.services
910
import workflows.transport
11+
from workflows.transport.common_transport import CommonTransport
1012

1113

1214
class ServiceStarter:
@@ -27,12 +29,14 @@ def on_parsing(options, args):
2729
"""
2830

2931
@staticmethod
30-
def on_transport_factory_preparation(transport_factory):
32+
def on_transport_factory_preparation(
33+
transport_factory,
34+
) -> Callable[[], CommonTransport] | None:
3135
"""Plugin hook to intercept/manipulate newly created Transport factories
3236
before first invocation."""
3337

3438
@staticmethod
35-
def on_transport_preparation(transport):
39+
def on_transport_preparation(transport: CommonTransport) -> CommonTransport | None:
3640
"""Plugin hook to intercept/manipulate newly created Transport objects
3741
before connecting."""
3842

@@ -136,7 +140,9 @@ def run(
136140
parser.error(f"Please specify a service name. {known_services_help}")
137141

138142
# Create Transport factory
139-
transport_factory = workflows.transport.lookup(options.transport)
143+
transport_factory: Callable[[], CommonTransport] = workflows.transport.lookup(
144+
options.transport
145+
)
140146

141147
# Call on_transport_factory_preparation hook
142148
transport_factory = (
@@ -147,7 +153,7 @@ def run(
147153
# Set up on_transport_preparation hook to affect newly created transport objects
148154
true_transport_factory = transport_factory
149155

150-
def on_transport_preparation_hook():
156+
def on_transport_preparation_hook() -> CommonTransport:
151157
transport_object = true_transport_factory()
152158
return self.on_transport_preparation(transport_object) or transport_object
153159

src/workflows/frontend/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
import multiprocessing
55
import threading
66
import time
7+
from collections.abc import Callable
78

89
import workflows
910
import workflows.frontend.utilization
1011
import workflows.services
1112
import workflows.transport
1213
import workflows.util
1314
from workflows.services.common_service import CommonService
15+
from workflows.transport.common_transport import CommonTransport
1416

1517
basestring = (str, bytes)
1618

@@ -22,9 +24,11 @@ class Frontend:
2224
service.
2325
"""
2426

27+
_transport_factory: Callable[[], CommonTransport]
28+
2529
def __init__(
2630
self,
27-
transport=None,
31+
transport: Callable[[], CommonTransport] | str | None = None,
2832
service=None,
2933
transport_command_channel=None,
3034
restart_service=False,

0 commit comments

Comments
 (0)