Skip to content

Commit 992534f

Browse files
committed
lint + formatter
Signed-off-by: Tim Li <[email protected]>
1 parent 1f0259d commit 992534f

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

cadence/workflow.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@ class WorkflowDefinition:
5959
Provides type safety and metadata for workflow classes.
6060
"""
6161

62-
def __init__(self, cls: Type, name: str, run_method_name: str, signals: dict[str, Callable[..., Any]]):
62+
def __init__(
63+
self,
64+
cls: Type,
65+
name: str,
66+
run_method_name: str,
67+
signals: dict[str, Callable[..., Any]],
68+
):
6369
self._cls = cls
6470
self._name = name
6571
self._run_method_name = run_method_name
@@ -106,7 +112,9 @@ def wrap(cls: Type, opts: WorkflowDefinitionOptions) -> "WorkflowDefinition":
106112
# Validate that the class has exactly one run method and find it
107113
# Also validate that class does not have multiple signal methods with the same name
108114
signals: dict[str, Callable[..., Any]] = {}
109-
signal_names: dict[str, str] = {} # Map signal name to method name for duplicate detection
115+
signal_names: dict[
116+
str, str
117+
] = {} # Map signal name to method name for duplicate detection
110118
run_method_name = None
111119
for attr_name in dir(cls):
112120
if attr_name.startswith("_"):
@@ -123,7 +131,7 @@ def wrap(cls: Type, opts: WorkflowDefinitionOptions) -> "WorkflowDefinition":
123131
f"Multiple @workflow.run methods found in class {cls.__name__}"
124132
)
125133
run_method_name = attr_name
126-
134+
127135
if hasattr(attr, "_workflow_signal"):
128136
signal_name = getattr(attr, "_workflow_signal")
129137
if signal_name in signal_names:
@@ -140,7 +148,6 @@ def wrap(cls: Type, opts: WorkflowDefinitionOptions) -> "WorkflowDefinition":
140148
return WorkflowDefinition(cls, name, run_method_name, signals)
141149

142150

143-
144151
def run(func: Optional[T] = None) -> Union[T, Callable[[T], T]]:
145152
"""
146153
Decorator to mark a method as the main workflow run method.
@@ -181,12 +188,13 @@ def decorator(f: T) -> T:
181188
# Called without parentheses: @workflow.run
182189
return decorator(func)
183190

191+
184192
def signal(name: str | None = None) -> Callable[[T], T]:
185193
"""
186194
Decorator to mark a method as a workflow signal handler.
187195
188196
Example:
189-
@workflow.signal(name="approval_channel")
197+
@workflow.signal(name="approval_channel")
190198
async def approve(self, approved: bool):
191199
self.approved = approved
192200
@@ -205,10 +213,12 @@ async def approve(self, approved: bool):
205213

206214
def decorator(f: T) -> T:
207215
f._workflow_signal = name # type: ignore
208-
return f
216+
return f
217+
209218
# Only allow @workflow.signal(name), require name to be explicitly provided
210219
return decorator
211220

221+
212222
@dataclass
213223
class WorkflowInfo:
214224
workflow_type: str

tests/cadence/worker/test_registry.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,19 @@ async def handle_cancel(self):
256256
assert len(workflow_def.signals) == 2
257257
assert "handle_approval" in workflow_def.signals
258258
assert "handle_cancel" in workflow_def.signals
259-
assert getattr(workflow_def.signals["handle_approval"], "_workflow_signal") == "approval"
260-
assert getattr(workflow_def.signals["handle_cancel"], "_workflow_signal") == "cancel"
259+
assert (
260+
getattr(workflow_def.signals["handle_approval"], "_workflow_signal")
261+
== "approval"
262+
)
263+
assert (
264+
getattr(workflow_def.signals["handle_cancel"], "_workflow_signal")
265+
== "cancel"
266+
)
261267

262268
def test_signal_decorator_requires_name(self):
263269
"""Test that signal decorator requires name parameter."""
264270
with pytest.raises(ValueError, match="name is required"):
271+
265272
@workflow.signal()
266273
async def test_signal(self):
267274
pass
@@ -284,7 +291,10 @@ def test_duplicate_signal_names_error(self):
284291
"""Test that duplicate signal names raise ValueError."""
285292
reg = Registry()
286293

287-
with pytest.raises(ValueError, match="Multiple.*signal.*found.*with signal name 'approval'"):
294+
with pytest.raises(
295+
ValueError, match="Multiple.*signal.*found.*with signal name 'approval'"
296+
):
297+
288298
@reg.workflow
289299
class WorkflowWithDuplicateSignalNames:
290300
@workflow.run

0 commit comments

Comments
 (0)