diff --git a/temporalio/worker/_interceptor.py b/temporalio/worker/_interceptor.py index e2706930..a3146200 100644 --- a/temporalio/worker/_interceptor.py +++ b/temporalio/worker/_interceptor.py @@ -388,7 +388,7 @@ async def signal_external_workflow( def start_activity( self, input: StartActivityInput - ) -> temporalio.workflow.ActivityHandle: + ) -> temporalio.workflow.ActivityHandle[Any]: """Called for every :py:func:`temporalio.workflow.start_activity` and :py:func:`temporalio.workflow.execute_activity` call. """ @@ -396,7 +396,7 @@ def start_activity( async def start_child_workflow( self, input: StartChildWorkflowInput - ) -> temporalio.workflow.ChildWorkflowHandle: + ) -> temporalio.workflow.ChildWorkflowHandle[Any, Any]: """Called for every :py:func:`temporalio.workflow.start_child_workflow` and :py:func:`temporalio.workflow.execute_child_workflow` call. """ @@ -404,7 +404,7 @@ async def start_child_workflow( def start_local_activity( self, input: StartLocalActivityInput - ) -> temporalio.workflow.ActivityHandle: + ) -> temporalio.workflow.ActivityHandle[Any]: """Called for every :py:func:`temporalio.workflow.start_local_activity` and :py:func:`temporalio.workflow.execute_local_activity` call. """ diff --git a/temporalio/worker/_workflow_instance.py b/temporalio/worker/_workflow_instance.py index 4c9e69dd..ec229c71 100644 --- a/temporalio/worker/_workflow_instance.py +++ b/temporalio/worker/_workflow_instance.py @@ -1543,12 +1543,10 @@ def _outbound_schedule_activity( "Activity must have start_to_close_timeout or schedule_to_close_timeout" ) - handle: Optional[_ActivityHandle] = None + handle: _ActivityHandle # Function that runs in the handle async def run_activity() -> Any: - nonlocal handle - assert handle while True: # Mark it as started each loop because backoff could cause it to # be marked as unstarted @@ -1615,12 +1613,10 @@ async def _outbound_signal_external_workflow( async def _outbound_start_child_workflow( self, input: StartChildWorkflowInput ) -> _ChildWorkflowHandle: - handle: Optional[_ChildWorkflowHandle] = None + handle: _ChildWorkflowHandle # Common code for handling cancel for start and run def apply_child_cancel_error() -> None: - nonlocal handle - assert handle # Send a cancel request to the child cancel_command = self._add_command() handle._apply_cancel_command(cancel_command) @@ -1638,9 +1634,7 @@ def apply_child_cancel_error() -> None: # Function that runs in the handle async def run_child() -> Any: - nonlocal handle while True: - assert handle try: # We have to shield because we don't want the future itself # to be cancelled @@ -2391,17 +2385,17 @@ async def signal_external_workflow( def start_activity( self, input: StartActivityInput - ) -> temporalio.workflow.ActivityHandle: + ) -> temporalio.workflow.ActivityHandle[Any]: return self._instance._outbound_schedule_activity(input) async def start_child_workflow( self, input: StartChildWorkflowInput - ) -> temporalio.workflow.ChildWorkflowHandle: + ) -> temporalio.workflow.ChildWorkflowHandle[Any, Any]: return await self._instance._outbound_start_child_workflow(input) def start_local_activity( self, input: StartLocalActivityInput - ) -> temporalio.workflow.ActivityHandle: + ) -> temporalio.workflow.ActivityHandle[Any]: return self._instance._outbound_schedule_activity(input) diff --git a/tests/helpers/__init__.py b/tests/helpers/__init__.py index 48eb03f5..da525974 100644 --- a/tests/helpers/__init__.py +++ b/tests/helpers/__init__.py @@ -4,7 +4,7 @@ import uuid from contextlib import closing from datetime import timedelta -from typing import Any, Awaitable, Callable, Optional, Sequence, Type, TypeVar, Union +from typing import Any, Awaitable, Callable, Optional, Sequence, Type, TypeVar from temporalio.api.common.v1 import WorkflowExecution from temporalio.api.enums.v1 import IndexedValueType