Skip to content

Commit a02c6c9

Browse files
committed
Clean up existing code
1 parent e360398 commit a02c6c9

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

temporalio/worker/_interceptor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,23 +388,23 @@ async def signal_external_workflow(
388388

389389
def start_activity(
390390
self, input: StartActivityInput
391-
) -> temporalio.workflow.ActivityHandle:
391+
) -> temporalio.workflow.ActivityHandle[Any]:
392392
"""Called for every :py:func:`temporalio.workflow.start_activity` and
393393
:py:func:`temporalio.workflow.execute_activity` call.
394394
"""
395395
return self.next.start_activity(input)
396396

397397
async def start_child_workflow(
398398
self, input: StartChildWorkflowInput
399-
) -> temporalio.workflow.ChildWorkflowHandle:
399+
) -> temporalio.workflow.ChildWorkflowHandle[Any, Any]:
400400
"""Called for every :py:func:`temporalio.workflow.start_child_workflow`
401401
and :py:func:`temporalio.workflow.execute_child_workflow` call.
402402
"""
403403
return await self.next.start_child_workflow(input)
404404

405405
def start_local_activity(
406406
self, input: StartLocalActivityInput
407-
) -> temporalio.workflow.ActivityHandle:
407+
) -> temporalio.workflow.ActivityHandle[Any]:
408408
"""Called for every :py:func:`temporalio.workflow.start_local_activity`
409409
and :py:func:`temporalio.workflow.execute_local_activity` call.
410410
"""

temporalio/worker/_workflow_instance.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,12 +1543,10 @@ def _outbound_schedule_activity(
15431543
"Activity must have start_to_close_timeout or schedule_to_close_timeout"
15441544
)
15451545

1546-
handle: Optional[_ActivityHandle] = None
1546+
handle: _ActivityHandle
15471547

15481548
# Function that runs in the handle
15491549
async def run_activity() -> Any:
1550-
nonlocal handle
1551-
assert handle
15521550
while True:
15531551
# Mark it as started each loop because backoff could cause it to
15541552
# be marked as unstarted
@@ -1615,12 +1613,10 @@ async def _outbound_signal_external_workflow(
16151613
async def _outbound_start_child_workflow(
16161614
self, input: StartChildWorkflowInput
16171615
) -> _ChildWorkflowHandle:
1618-
handle: Optional[_ChildWorkflowHandle] = None
1616+
handle: _ChildWorkflowHandle
16191617

16201618
# Common code for handling cancel for start and run
16211619
def apply_child_cancel_error() -> None:
1622-
nonlocal handle
1623-
assert handle
16241620
# Send a cancel request to the child
16251621
cancel_command = self._add_command()
16261622
handle._apply_cancel_command(cancel_command)
@@ -1638,9 +1634,7 @@ def apply_child_cancel_error() -> None:
16381634

16391635
# Function that runs in the handle
16401636
async def run_child() -> Any:
1641-
nonlocal handle
16421637
while True:
1643-
assert handle
16441638
try:
16451639
# We have to shield because we don't want the future itself
16461640
# to be cancelled
@@ -2391,17 +2385,17 @@ async def signal_external_workflow(
23912385

23922386
def start_activity(
23932387
self, input: StartActivityInput
2394-
) -> temporalio.workflow.ActivityHandle:
2388+
) -> temporalio.workflow.ActivityHandle[Any]:
23952389
return self._instance._outbound_schedule_activity(input)
23962390

23972391
async def start_child_workflow(
23982392
self, input: StartChildWorkflowInput
2399-
) -> temporalio.workflow.ChildWorkflowHandle:
2393+
) -> temporalio.workflow.ChildWorkflowHandle[Any, Any]:
24002394
return await self._instance._outbound_start_child_workflow(input)
24012395

24022396
def start_local_activity(
24032397
self, input: StartLocalActivityInput
2404-
) -> temporalio.workflow.ActivityHandle:
2398+
) -> temporalio.workflow.ActivityHandle[Any]:
24052399
return self._instance._outbound_schedule_activity(input)
24062400

24072401

tests/helpers/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import uuid
55
from contextlib import closing
66
from datetime import timedelta
7-
from typing import Any, Awaitable, Callable, Optional, Sequence, Type, TypeVar, Union
7+
from typing import Any, Awaitable, Callable, Optional, Sequence, Type, TypeVar
88

99
from temporalio.api.common.v1 import WorkflowExecution
1010
from temporalio.api.enums.v1 import IndexedValueType

0 commit comments

Comments
 (0)