Skip to content

Commit 488fa66

Browse files
committed
Linting / mypy
1 parent d1e0681 commit 488fa66

File tree

7 files changed

+45
-20
lines changed

7 files changed

+45
-20
lines changed

temporalio/client.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import inspect
99
import json
1010
import re
11+
import sys
1112
import uuid
1213
import warnings
1314
from abc import ABC, abstractmethod
@@ -1668,7 +1669,7 @@ async def start_update(
16681669
*,
16691670
args: Sequence[Any] = [],
16701671
id: Optional[str] = None,
1671-
wait_for_stage: temporalio.api.enums.v1.UpdateWorkflowExecutionLifecycleStage = temporalio.api.enums.v1.UpdateWorkflowExecutionLifecycleStage.UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_ADMITTED,
1672+
wait_for_stage: temporalio.api.enums.v1.UpdateWorkflowExecutionLifecycleStage.ValueType = temporalio.api.enums.v1.UpdateWorkflowExecutionLifecycleStage.UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_ADMITTED,
16721673
result_type: Optional[Type] = None,
16731674
rpc_metadata: Mapping[str, str] = {},
16741675
rpc_timeout: Optional[timedelta] = None,
@@ -2815,8 +2816,8 @@ class ScheduleActionStartWorkflow(ScheduleAction):
28152816

28162817
@staticmethod
28172818
def _from_proto(
2818-
info: temporalio.api.workflow.v1.NewWorkflowExecutionInfo,
2819-
) -> ScheduleActionStartWorkflow: # type: ignore[override]
2819+
info: temporalio.api.workflow.v1.NewWorkflowExecutionInfo, # type: ignore[override]
2820+
) -> ScheduleActionStartWorkflow:
28202821
return ScheduleActionStartWorkflow("<unset>", raw_info=info)
28212822

28222823
# Overload for no-param workflow
@@ -3797,13 +3798,18 @@ def __init__(
37973798
run_id: Optional[str] = None,
37983799
result_type: Optional[Type] = None,
37993800
):
3801+
"""Create a workflow update handle.
3802+
3803+
Users should not create this directly, but rather use
3804+
:py:meth:`Client.start_workflow_update`.
3805+
"""
38003806
self._client = client
38013807
self._id = id
38023808
self._name = name
38033809
self._workflow_id = workflow_id
38043810
self._run_id = run_id
38053811
self._result_type = result_type
3806-
self._known_result = None
3812+
self._known_result: Optional[temporalio.api.update.v1.Outcome] = None
38073813

38083814
@property
38093815
def id(self) -> str:
@@ -3829,7 +3835,7 @@ async def result(
38293835
self,
38303836
*,
38313837
timeout: Optional[timedelta] = None,
3832-
rpc_metadata: Mapping[str, str] = None,
3838+
rpc_metadata: Mapping[str, str] = {},
38333839
rpc_timeout: Optional[timedelta] = None,
38343840
) -> Any:
38353841
"""Wait for and return the result of the update. The result may already be known in which case no call is made.
@@ -4084,7 +4090,7 @@ class UpdateWorkflowInput:
40844090
update: str
40854091
args: Sequence[Any]
40864092
wait_for_stage: Optional[
4087-
temporalio.api.enums.v1.UpdateWorkflowExecutionLifecycleStage
4093+
temporalio.api.enums.v1.UpdateWorkflowExecutionLifecycleStage.ValueType
40884094
]
40894095
headers: Mapping[str, temporalio.api.common.v1.Payload]
40904096
ret_type: Optional[Type]
@@ -4724,9 +4730,7 @@ async def start_workflow_update(
47244730
# If the status is INVALID_ARGUMENT, we can assume it's an update
47254731
# failed error
47264732
if err.status == RPCStatusCode.INVALID_ARGUMENT:
4727-
raise WorkflowUpdateFailedError(
4728-
input.workflow_id, input.update, err.cause
4729-
)
4733+
raise WorkflowUpdateFailedError(input.workflow_id, input.update, err)
47304734
else:
47314735
raise
47324736

@@ -4760,7 +4764,9 @@ async def poll_workflow_update(self, input: PollUpdateWorkflowInput) -> Any:
47604764
)
47614765
try:
47624766
# Wait for at most the *overall* timeout
4763-
async with asyncio.timeout(input.timeout.total_seconds()):
4767+
async with asyncio.timeout(
4768+
input.timeout.total_seconds() if input.timeout else sys.float_info.max
4769+
):
47644770
# Continue polling as long as we have either an empty response, or an *rpc* timeout
47654771
while True:
47664772
try:

temporalio/contrib/opentelemetry.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import opentelemetry.trace
2626
import opentelemetry.trace.propagation.tracecontext
2727
import opentelemetry.util.types
28+
from client import PollUpdateWorkflowInput, WorkflowUpdateHandle
2829
from typing_extensions import Protocol, TypeAlias, TypedDict
2930

3031
import temporalio.activity
@@ -244,16 +245,25 @@ async def signal_workflow(
244245
):
245246
return await super().signal_workflow(input)
246247

247-
async def update_workflow(
248+
async def start_workflow_update(
248249
self, input: temporalio.client.UpdateWorkflowInput
249-
) -> Any:
250+
) -> WorkflowUpdateHandle:
251+
with self.root._start_as_current_span(
252+
f"StartWorkflowUpdate:{input.update}",
253+
attributes={"temporalWorkflowID": input.workflow_id},
254+
input=input,
255+
kind=opentelemetry.trace.SpanKind.CLIENT,
256+
):
257+
return await super().start_workflow_update(input)
258+
259+
async def poll_workflow_update(self, input: PollUpdateWorkflowInput) -> Any:
250260
with self.root._start_as_current_span(
251-
f"UpdateWorkflow:{input.update}",
261+
f"PollWorkflowUpdate:{input.update}",
252262
attributes={"temporalWorkflowID": input.workflow_id},
253263
input=input,
254264
kind=opentelemetry.trace.SpanKind.CLIENT,
255265
):
256-
return await super().update_workflow(input)
266+
return await super().poll_workflow_update(input)
257267

258268

259269
class _TracingActivityInboundInterceptor(temporalio.worker.ActivityInboundInterceptor):

temporalio/worker/_interceptor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ class HandleQueryInput:
193193
@dataclass
194194
class HandleUpdateInput:
195195
"""Input for :py:meth:`WorkflowInboundInterceptor.handle_update_validator`
196-
and :py:meth:`WorkflowInboundInterceptor.handle_update_handler`."""
196+
and :py:meth:`WorkflowInboundInterceptor.handle_update_handler`.
197+
"""
197198

198199
id: str
199200
update: str

temporalio/worker/_workflow_instance.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,14 +452,15 @@ async def run_update(
452452
accpetance_command: temporalio.bridge.proto.workflow_commands.WorkflowCommand,
453453
) -> None:
454454
command = accpetance_command
455+
assert defn is not None
455456
try:
456457
if defn.validator is not None:
457458
# Run the validator
458459
await self._inbound.handle_update_validator(handler_input)
459460

460461
# Accept the update
461462
command.update_response.accepted.SetInParent()
462-
command = None
463+
command = None # type: ignore
463464

464465
# Run the handler
465466
success = await self._inbound.handle_update_handler(handler_input)

temporalio/workflow.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,8 @@ def _update_validator(
811811
update_def: _UpdateDefinition, fn: Optional[Callable[..., None]] = None
812812
):
813813
"""Decorator for a workflow update validator method."""
814-
update_def.set_validator(fn)
814+
if fn is not None:
815+
update_def.set_validator(fn)
815816

816817

817818
def upsert_search_attributes(attributes: temporalio.common.SearchAttributes) -> None:
@@ -1375,7 +1376,9 @@ def bind_fn(self, obj: Any) -> Callable[..., Any]:
13751376
return _bind_method(obj, self.fn)
13761377

13771378
def bind_validator(self, obj: Any) -> Callable[..., Any]:
1378-
return _bind_method(obj, self.validator)
1379+
if self.validator is not None:
1380+
return _bind_method(obj, self.validator)
1381+
return lambda *args, **kwargs: None
13791382

13801383
def set_validator(self, validator: Callable[..., None]) -> None:
13811384
# TODO: Verify arg types are the same

tests/test_workflow.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ def test_workflow_defn_good():
8787
name="base_query", fn=GoodDefnBase.base_query, is_method=True
8888
),
8989
},
90+
# TODO: Add
91+
updates={},
9092
sandboxed=True,
9193
)
9294

tests/worker/test_workflow.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3541,7 +3541,7 @@ async def last_event_async(self, an_arg: str) -> str:
35413541

35423542
@workflow.update
35433543
async def runs_activity(self, name: str) -> str:
3544-
act = workflow.start_activity_method(
3544+
act = workflow.start_activity(
35453545
say_hello, name, schedule_to_close_timeout=timedelta(seconds=5)
35463546
)
35473547
act.cancel()
@@ -3565,7 +3565,9 @@ async def runs_activity(self, name: str) -> str:
35653565

35663566

35673567
async def test_workflow_update_handlers(client: Client):
3568-
async with new_worker(client, UpdateHandlersWorkflow) as worker:
3568+
async with new_worker(
3569+
client, UpdateHandlersWorkflow, activities=[say_hello]
3570+
) as worker:
35693571
handle = await client.start_workflow(
35703572
UpdateHandlersWorkflow.run,
35713573
id=f"update-handlers-workflow-{uuid.uuid4()}",

0 commit comments

Comments
 (0)