Skip to content

Minor cleanup #861

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions temporalio/worker/_interceptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,23 +388,23 @@ 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.
"""
return self.next.start_activity(input)

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.
"""
return await self.next.start_child_workflow(input)

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.
"""
Expand Down
16 changes: 5 additions & 11 deletions temporalio/worker/_workflow_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, can the static analyzer know that this is set before used? Or do the Python static analyzers not check whether a value is set before use?


# 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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading