Skip to content

Commit 4688467

Browse files
committed
Clean up existing code
1 parent 5afb131 commit 4688467

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
@@ -1590,12 +1590,10 @@ def _outbound_schedule_activity(
15901590
"Activity must have start_to_close_timeout or schedule_to_close_timeout"
15911591
)
15921592

1593-
handle: Optional[_ActivityHandle] = None
1593+
handle: _ActivityHandle
15941594

15951595
# Function that runs in the handle
15961596
async def run_activity() -> Any:
1597-
nonlocal handle
1598-
assert handle
15991597
while True:
16001598
# Mark it as started each loop because backoff could cause it to
16011599
# be marked as unstarted
@@ -1662,12 +1660,10 @@ async def _outbound_signal_external_workflow(
16621660
async def _outbound_start_child_workflow(
16631661
self, input: StartChildWorkflowInput
16641662
) -> _ChildWorkflowHandle:
1665-
handle: Optional[_ChildWorkflowHandle] = None
1663+
handle: _ChildWorkflowHandle
16661664

16671665
# Common code for handling cancel for start and run
16681666
def apply_child_cancel_error() -> None:
1669-
nonlocal handle
1670-
assert handle
16711667
# Send a cancel request to the child
16721668
cancel_command = self._add_command()
16731669
handle._apply_cancel_command(cancel_command)
@@ -1685,9 +1681,7 @@ def apply_child_cancel_error() -> None:
16851681

16861682
# Function that runs in the handle
16871683
async def run_child() -> Any:
1688-
nonlocal handle
16891684
while True:
1690-
assert handle
16911685
try:
16921686
# We have to shield because we don't want the future itself
16931687
# to be cancelled
@@ -2438,17 +2432,17 @@ async def signal_external_workflow(
24382432

24392433
def start_activity(
24402434
self, input: StartActivityInput
2441-
) -> temporalio.workflow.ActivityHandle:
2435+
) -> temporalio.workflow.ActivityHandle[Any]:
24422436
return self._instance._outbound_schedule_activity(input)
24432437

24442438
async def start_child_workflow(
24452439
self, input: StartChildWorkflowInput
2446-
) -> temporalio.workflow.ChildWorkflowHandle:
2440+
) -> temporalio.workflow.ChildWorkflowHandle[Any, Any]:
24472441
return await self._instance._outbound_start_child_workflow(input)
24482442

24492443
def start_local_activity(
24502444
self, input: StartLocalActivityInput
2451-
) -> temporalio.workflow.ActivityHandle:
2445+
) -> temporalio.workflow.ActivityHandle[Any]:
24522446
return self._instance._outbound_schedule_activity(input)
24532447

24542448

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)