Skip to content

Commit 3443f81

Browse files
committed
Linting
1 parent 83acfe6 commit 3443f81

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

temporalio/worker/_workflow_instance.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ class WorkflowInstanceDetails:
145145
worker_level_failure_exception_types: Sequence[Type[BaseException]]
146146
last_completion_result: temporalio.api.common.v1.Payloads
147147

148+
148149
class WorkflowInstance(ABC):
149150
"""Instance of a workflow that can handle activations."""
150151

@@ -1688,14 +1689,25 @@ def workflow_set_current_details(self, details: str):
16881689
self._assert_not_read_only("set current details")
16891690
self._current_details = details
16901691

1691-
def workflow_last_completion_result(self, type_hint: Optional[Type]) -> Optional[Any]:
1692+
def workflow_last_completion_result(
1693+
self, type_hint: Optional[Type]
1694+
) -> Optional[Any]:
16921695
if len(self._last_completion_result.payloads) == 0:
16931696
return None
16941697
elif len(self._last_completion_result.payloads) > 1:
1695-
warnings.warn(f"Expected single last completion result, got {len(self._last_completion_result.payloads)}")
1698+
warnings.warn(
1699+
f"Expected single last completion result, got {len(self._last_completion_result.payloads)}"
1700+
)
16961701
return None
16971702

1698-
return self._payload_converter.from_payload(self._last_completion_result.payloads[0], type_hint)
1703+
if type_hint is None:
1704+
return self._payload_converter.from_payload(
1705+
self._last_completion_result.payloads[0]
1706+
)
1707+
else:
1708+
return self._payload_converter.from_payload(
1709+
self._last_completion_result.payloads[0], type_hint
1710+
)
16991711

17001712
#### Calls from outbound impl ####
17011713
# These are in alphabetical order and all start with "_outbound_".

temporalio/worker/workflow_sandbox/_runner.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import temporalio.worker._workflow_instance
1919
import temporalio.workflow
2020

21+
from ...api.common.v1.message_pb2 import Payloads
22+
2123
# Workflow instance has to be relative import
2224
from .._workflow_instance import (
2325
UnsandboxedWorkflowRunner,
@@ -27,7 +29,6 @@
2729
)
2830
from ._importer import Importer
2931
from ._restrictions import RestrictionContext, SandboxRestrictions
30-
from ...api.common.v1.message_pb2 import Payloads
3132

3233
_fake_info = temporalio.workflow.Info(
3334
attempt=-1,

temporalio/workflow.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,9 @@ def workflow_get_current_details(self) -> str: ...
898898
def workflow_set_current_details(self, details: str): ...
899899

900900
@abstractmethod
901-
def workflow_last_completion_result(self, type_hint: Optional[Type]) -> Optional[Any]: ...
901+
def workflow_last_completion_result(
902+
self, type_hint: Optional[Type]
903+
) -> Optional[Any]: ...
902904

903905

904906
_current_update_info: contextvars.ContextVar[UpdateInfo] = contextvars.ContextVar(
@@ -1042,6 +1044,10 @@ def get_current_details() -> str:
10421044
return _Runtime.current().workflow_get_current_details()
10431045

10441046

1047+
@overload
1048+
def get_last_completion_result() -> Optional[Any]: ...
1049+
1050+
10451051
@overload
10461052
def get_last_completion_result(type_hint: Type[ParamType]) -> Optional[ParamType]: ...
10471053

tests/test_client.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55
import uuid
66
from datetime import datetime, timedelta, timezone
7-
from typing import Any, List, Mapping, Optional, cast, Tuple
7+
from typing import Any, List, Mapping, Optional, Tuple, cast
88
from unittest import mock
99

1010
import google.protobuf.any_pb2
@@ -92,9 +92,10 @@
9292
from temporalio.testing import WorkflowEnvironment
9393
from tests.helpers import (
9494
assert_eq_eventually,
95+
assert_eventually,
9596
ensure_search_attributes_present,
9697
new_worker,
97-
worker_versioning_enabled, assert_eventually,
98+
worker_versioning_enabled,
9899
)
99100
from tests.helpers.worker import (
100101
ExternalWorker,
@@ -1534,20 +1535,26 @@ async def test_schedule_last_completion_result(
15341535
),
15351536
)
15361537
await handle.trigger()
1538+
15371539
async def get_schedule_result() -> Tuple[int, Optional[str]]:
15381540
desc = await handle.describe()
15391541
length = len(desc.info.recent_actions)
15401542
if length == 0:
15411543
return length, None
15421544
else:
1543-
workflow_id = cast(ScheduleActionExecutionStartWorkflow, desc.info.recent_actions[-1].action).workflow_id
1545+
workflow_id = cast(
1546+
ScheduleActionExecutionStartWorkflow,
1547+
desc.info.recent_actions[-1].action,
1548+
).workflow_id
15441549
workflow_handle = client.get_workflow_handle(workflow_id)
15451550
result = await workflow_handle.result()
15461551
return length, result
15471552

15481553
assert await get_schedule_result() == (1, "My First Result")
15491554
await handle.trigger()
1550-
assert await get_schedule_result() == (2, "From last completion: My First Result")
1555+
assert await get_schedule_result() == (
1556+
2,
1557+
"From last completion: My First Result",
1558+
)
15511559

15521560
await handle.delete()
1553-

0 commit comments

Comments
 (0)