From d6b43fe19fcfe865341e586903c670f76b1d24c6 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Mon, 26 Aug 2024 09:05:45 -0400 Subject: [PATCH] Make client.py typecheck under pyright --- pyproject.toml | 1 - temporalio/client.py | 30 ++++++++++++------------- temporalio/worker/_workflow.py | 3 --- temporalio/worker/_workflow_instance.py | 4 ++-- tests/helpers/external_coroutine.py | 6 ++--- 5 files changed, 19 insertions(+), 25 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 902916cf..b3e3d6c9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -183,7 +183,6 @@ exclude = [ "temporalio/bridge/proto", "tests/worker/workflow_sandbox/testmodules/proto", "temporalio/bridge/worker.py", - "temporalio/client.py", "temporalio/contrib/opentelemetry.py", "temporalio/converter.py", "temporalio/testing/_workflow.py", diff --git a/temporalio/client.py b/temporalio/client.py index d15b9ea5..79746ae3 100644 --- a/temporalio/client.py +++ b/temporalio/client.py @@ -35,7 +35,7 @@ import google.protobuf.duration_pb2 import google.protobuf.json_format import google.protobuf.timestamp_pb2 -from typing_extensions import Concatenate, TypedDict +from typing_extensions import Concatenate, Required, TypedDict import temporalio.api.common.v1 import temporalio.api.enums.v1 @@ -1112,12 +1112,12 @@ async def get_worker_task_reachability( class ClientConfig(TypedDict, total=False): """TypedDict of config originally passed to :py:meth:`Client`.""" - service_client: temporalio.service.ServiceClient - namespace: str - data_converter: temporalio.converter.DataConverter - interceptors: Sequence[Interceptor] - default_workflow_query_reject_condition: Optional[ - temporalio.common.QueryRejectCondition + service_client: Required[temporalio.service.ServiceClient] + namespace: Required[str] + data_converter: Required[temporalio.converter.DataConverter] + interceptors: Required[Sequence[Interceptor]] + default_workflow_query_reject_condition: Required[ + Optional[temporalio.common.QueryRejectCondition] ] @@ -1797,7 +1797,7 @@ async def execute_update( MultiParamSpec, LocalReturnType ], *, - args: MultiParamSpec.args, + args: MultiParamSpec.args, # pyright: ignore id: Optional[str] = None, rpc_metadata: Mapping[str, str] = {}, rpc_timeout: Optional[timedelta] = None, @@ -1906,7 +1906,7 @@ async def start_update( MultiParamSpec, LocalReturnType ], *, - args: MultiParamSpec.args, + args: MultiParamSpec.args, # pyright: ignore wait_for_stage: WorkflowUpdateStage, id: Optional[str] = None, rpc_metadata: Mapping[str, str] = {}, @@ -3489,7 +3489,7 @@ class ScheduleOverlapPolicy(IntEnum): """ SKIP = int( - temporalio.api.enums.v1.ScheduleOverlapPolicy.SCHEDULE_OVERLAP_POLICY_SKIP + temporalio.api.enums.v1.ScheduleOverlapPolicy.SCHEDULE_OVERLAP_POLICY_SKIP # pyright: ignore ) """Don't start anything. @@ -3498,7 +3498,7 @@ class ScheduleOverlapPolicy(IntEnum): """ BUFFER_ONE = int( - temporalio.api.enums.v1.ScheduleOverlapPolicy.SCHEDULE_OVERLAP_POLICY_BUFFER_ONE + temporalio.api.enums.v1.ScheduleOverlapPolicy.SCHEDULE_OVERLAP_POLICY_BUFFER_ONE # pyright: ignore ) """Start the workflow again soon as the current one completes, but only buffer one start in this way. @@ -3509,25 +3509,25 @@ class ScheduleOverlapPolicy(IntEnum): """ BUFFER_ALL = int( - temporalio.api.enums.v1.ScheduleOverlapPolicy.SCHEDULE_OVERLAP_POLICY_BUFFER_ALL + temporalio.api.enums.v1.ScheduleOverlapPolicy.SCHEDULE_OVERLAP_POLICY_BUFFER_ALL # pyright: ignore ) """Buffer up any number of starts to all happen sequentially, immediately after the running workflow completes.""" CANCEL_OTHER = int( - temporalio.api.enums.v1.ScheduleOverlapPolicy.SCHEDULE_OVERLAP_POLICY_CANCEL_OTHER + temporalio.api.enums.v1.ScheduleOverlapPolicy.SCHEDULE_OVERLAP_POLICY_CANCEL_OTHER # pyright: ignore ) """If there is another workflow running, cancel it, and start the new one after the old one completes cancellation.""" TERMINATE_OTHER = int( - temporalio.api.enums.v1.ScheduleOverlapPolicy.SCHEDULE_OVERLAP_POLICY_TERMINATE_OTHER + temporalio.api.enums.v1.ScheduleOverlapPolicy.SCHEDULE_OVERLAP_POLICY_TERMINATE_OTHER # pyright: ignore ) """If there is another workflow running, terminate it and start the new one immediately.""" ALLOW_ALL = int( - temporalio.api.enums.v1.ScheduleOverlapPolicy.SCHEDULE_OVERLAP_POLICY_ALLOW_ALL + temporalio.api.enums.v1.ScheduleOverlapPolicy.SCHEDULE_OVERLAP_POLICY_ALLOW_ALL # pyright: ignore ) """Start any number of concurrent workflows. diff --git a/temporalio/worker/_workflow.py b/temporalio/worker/_workflow.py index 079c7752..fc56713e 100644 --- a/temporalio/worker/_workflow.py +++ b/temporalio/worker/_workflow.py @@ -8,18 +8,15 @@ import os import sys from datetime import timezone -from threading import get_ident from types import TracebackType from typing import ( Callable, Dict, List, - Literal, MutableMapping, Optional, Sequence, Set, - Tuple, Type, ) diff --git a/temporalio/worker/_workflow_instance.py b/temporalio/worker/_workflow_instance.py index de54849c..f897e02e 100644 --- a/temporalio/worker/_workflow_instance.py +++ b/temporalio/worker/_workflow_instance.py @@ -587,7 +587,7 @@ async def run_update() -> None: else: self._current_activation_error = err return - except BaseException as err: + except BaseException: if self._deleting: if LOG_IGNORE_DURING_DELETE: logger.debug( @@ -883,7 +883,7 @@ async def run_workflow(input: ExecuteWorkflowInput) -> None: ) self._primary_task = self.create_task( self._run_top_level_workflow_function(run_workflow(input)), - name=f"run", + name="run", ) def _apply_update_random_seed( diff --git a/tests/helpers/external_coroutine.py b/tests/helpers/external_coroutine.py index 44c8d8ef..9af6e85e 100644 --- a/tests/helpers/external_coroutine.py +++ b/tests/helpers/external_coroutine.py @@ -2,17 +2,15 @@ File used in conjunction with external_stack_trace.py to test filenames in multi-file workflows. """ -from asyncio import sleep - from temporalio import workflow -async def never_completing_coroutine(status) -> None: +async def never_completing_coroutine(status: list[str]) -> None: status[0] = "waiting" # external coroutine test await workflow.wait_condition(lambda: False) -async def wait_on_timer(status) -> None: +async def wait_on_timer(status: list[str]) -> None: status[0] = "waiting" # multifile test print("Coroutine executed, waiting.") await workflow.wait_condition(lambda: False)