diff --git a/temporalio/client/_nexus.py b/temporalio/client/_nexus.py index 8cd95b26f..7eea155a9 100644 --- a/temporalio/client/_nexus.py +++ b/temporalio/client/_nexus.py @@ -619,7 +619,7 @@ async def start_operation( operation: Callable[ [ NexusServiceType, - temporalio.nexus.TemporalNexusStartOperationContext, + temporalio.nexus.TemporalStartOperationContext, temporalio.nexus.TemporalNexusClient, InputT, ], @@ -841,7 +841,7 @@ async def execute_operation( operation: Callable[ [ NexusServiceType, - temporalio.nexus.TemporalNexusStartOperationContext, + temporalio.nexus.TemporalStartOperationContext, temporalio.nexus.TemporalNexusClient, InputT, ], diff --git a/temporalio/nexus/__init__.py b/temporalio/nexus/__init__.py index f1a10767d..402e4b04e 100644 --- a/temporalio/nexus/__init__.py +++ b/temporalio/nexus/__init__.py @@ -4,7 +4,7 @@ """ from ._decorators import ( - TemporalNexusOperationStartHandlerFunc, + TemporalOperationStartHandlerFunc, temporal_operation, workflow_run_operation, ) @@ -12,8 +12,8 @@ Info, LoggerAdapter, NexusCallback, - TemporalNexusCancelOperationContext, - TemporalNexusStartOperationContext, + TemporalCancelOperationContext, + TemporalStartOperationContext, WorkflowRunOperationContext, client, in_operation, @@ -26,7 +26,7 @@ ) from ._operation_handlers import ( CancelWorkflowRunOptions, - TemporalNexusOperationHandler, + TemporalOperationHandler, ) from ._temporal_client import TemporalNexusClient, TemporalOperationResult from ._token import WorkflowHandle @@ -38,8 +38,8 @@ "LoggerAdapter", "NexusCallback", "WorkflowRunOperationContext", - "TemporalNexusCancelOperationContext", - "TemporalNexusStartOperationContext", + "TemporalCancelOperationContext", + "TemporalStartOperationContext", "client", "in_operation", "info", @@ -50,8 +50,8 @@ "wait_for_worker_shutdown_sync", "WorkflowHandle", "TemporalNexusClient", - "TemporalNexusOperationStartHandlerFunc", - "TemporalNexusOperationHandler", + "TemporalOperationStartHandlerFunc", + "TemporalOperationHandler", "TemporalOperationResult", "temporal_operation", ) diff --git a/temporalio/nexus/_decorators.py b/temporalio/nexus/_decorators.py index 3f1a322e7..2dd2b3554 100644 --- a/temporalio/nexus/_decorators.py +++ b/temporalio/nexus/_decorators.py @@ -21,11 +21,11 @@ from temporalio.types import NexusServiceType from ._operation_context import ( - TemporalNexusStartOperationContext, + TemporalStartOperationContext, WorkflowRunOperationContext, ) from ._operation_handlers import ( - TemporalNexusOperationHandler, + TemporalOperationHandler, WorkflowRunOperationHandler, ) from ._token import WorkflowHandle @@ -145,10 +145,10 @@ async def _start( return decorator(start) -TemporalNexusOperationStartHandlerFunc: TypeAlias = Callable[ +TemporalOperationStartHandlerFunc: TypeAlias = Callable[ [ NexusServiceType, - TemporalNexusStartOperationContext, + TemporalStartOperationContext, TemporalNexusClient, InputT, ], @@ -158,8 +158,8 @@ async def _start( @overload def temporal_operation( - start: TemporalNexusOperationStartHandlerFunc[NexusServiceType, InputT, OutputT], -) -> TemporalNexusOperationStartHandlerFunc[NexusServiceType, InputT, OutputT]: ... + start: TemporalOperationStartHandlerFunc[NexusServiceType, InputT, OutputT], +) -> TemporalOperationStartHandlerFunc[NexusServiceType, InputT, OutputT]: ... @overload @@ -167,21 +167,21 @@ def temporal_operation( *, name: str | None = None, ) -> Callable[ - [TemporalNexusOperationStartHandlerFunc[NexusServiceType, InputT, OutputT]], - TemporalNexusOperationStartHandlerFunc[NexusServiceType, InputT, OutputT], + [TemporalOperationStartHandlerFunc[NexusServiceType, InputT, OutputT]], + TemporalOperationStartHandlerFunc[NexusServiceType, InputT, OutputT], ]: ... def temporal_operation( start: None - | TemporalNexusOperationStartHandlerFunc[NexusServiceType, InputT, OutputT] = None, + | TemporalOperationStartHandlerFunc[NexusServiceType, InputT, OutputT] = None, *, name: str | None = None, ) -> ( - TemporalNexusOperationStartHandlerFunc[NexusServiceType, InputT, OutputT] + TemporalOperationStartHandlerFunc[NexusServiceType, InputT, OutputT] | Callable[ - [TemporalNexusOperationStartHandlerFunc[NexusServiceType, InputT, OutputT]], - TemporalNexusOperationStartHandlerFunc[NexusServiceType, InputT, OutputT], + [TemporalOperationStartHandlerFunc[NexusServiceType, InputT, OutputT]], + TemporalOperationStartHandlerFunc[NexusServiceType, InputT, OutputT], ] ): """Decorator marking a method as the start method for an operation that interacts with Temporal. @@ -191,10 +191,8 @@ def temporal_operation( """ def decorator( - start: TemporalNexusOperationStartHandlerFunc[ - NexusServiceType, InputT, OutputT - ], - ) -> TemporalNexusOperationStartHandlerFunc[NexusServiceType, InputT, OutputT]: + start: TemporalOperationStartHandlerFunc[NexusServiceType, InputT, OutputT], + ) -> TemporalOperationStartHandlerFunc[NexusServiceType, InputT, OutputT]: if not is_async_callable(start): raise RuntimeError( f"{start} is not an `async def` method. " @@ -209,7 +207,7 @@ def operation_handler_factory( self: NexusServiceType, ) -> OperationHandler[InputT, OutputT]: async def _start( - ctx: TemporalNexusStartOperationContext, + ctx: TemporalStartOperationContext, client: TemporalNexusClient, input: InputT, ) -> TemporalOperationResult[OutputT]: @@ -220,18 +218,18 @@ async def _start( input, ) - class _TemporalNexusOperationHandler(TemporalNexusOperationHandler): + class _TemporalOperationHandler(TemporalOperationHandler): @override async def start_operation( self, - ctx: TemporalNexusStartOperationContext, + ctx: TemporalStartOperationContext, client: TemporalNexusClient, input: InputT, ) -> TemporalOperationResult[OutputT]: return await _start(ctx, client, input) - _TemporalNexusOperationHandler.start_operation.__doc__ = start.__doc__ - return _TemporalNexusOperationHandler() + _TemporalOperationHandler.start_operation.__doc__ = start.__doc__ + return _TemporalOperationHandler() method_name = get_callable_name(start) op = nexusrpc.Operation( diff --git a/temporalio/nexus/_operation_context.py b/temporalio/nexus/_operation_context.py index e8ead61fe..01d209a9f 100644 --- a/temporalio/nexus/_operation_context.py +++ b/temporalio/nexus/_operation_context.py @@ -549,7 +549,7 @@ def set(self) -> None: _temporal_cancel_operation_context.set(self) -class TemporalNexusStartOperationContext(StartOperationContext): +class TemporalStartOperationContext(StartOperationContext): """Context received by a Temporal Nexus operation when it is started. .. warning:: @@ -563,7 +563,7 @@ def _from_start_operation_context(cls, ctx: StartOperationContext) -> Self: ) -class TemporalNexusCancelOperationContext(CancelOperationContext): +class TemporalCancelOperationContext(CancelOperationContext): """Context received by a Temporal Nexus operation when it is canceled. .. warning:: diff --git a/temporalio/nexus/_operation_handlers.py b/temporalio/nexus/_operation_handlers.py index c3e4b2e5e..e5c3bd762 100644 --- a/temporalio/nexus/_operation_handlers.py +++ b/temporalio/nexus/_operation_handlers.py @@ -21,8 +21,8 @@ import temporalio.nexus from temporalio.nexus._operation_context import ( - TemporalNexusCancelOperationContext, - TemporalNexusStartOperationContext, + TemporalCancelOperationContext, + TemporalStartOperationContext, _temporal_cancel_operation_context, ) from temporalio.nexus._temporal_client import ( @@ -127,8 +127,8 @@ async def _cancel_workflow( class CancelWorkflowRunOptions: """Options for cancelling the workflow backing a Nexus operation. - These options are built by :py:class:`TemporalNexusOperationHandler` and passed to - :py:meth:`TemporalNexusOperationHandler.cancel_workflow_run`. + These options are built by :py:class:`TemporalOperationHandler` and passed to + :py:meth:`TemporalOperationHandler.cancel_workflow_run`. .. warning:: This API is experimental and unstable. @@ -138,7 +138,7 @@ class CancelWorkflowRunOptions: """The ID of the workflow to cancel.""" -class TemporalNexusOperationHandler(OperationHandler[InputT, OutputT], ABC): +class TemporalOperationHandler(OperationHandler[InputT, OutputT], ABC): """Operation handler for Nexus operations that interact with Temporal. Implementations override the start_operation method. @@ -149,7 +149,7 @@ class TemporalNexusOperationHandler(OperationHandler[InputT, OutputT], ABC): @abstractmethod async def start_operation( self, - ctx: TemporalNexusStartOperationContext, + ctx: TemporalStartOperationContext, client: TemporalNexusClient, input: InputT, ) -> TemporalOperationResult[OutputT]: @@ -165,9 +165,7 @@ async def start( This API is experimental and unstable. """ nexus_client = _TemporalNexusClient() - start_ctx = TemporalNexusStartOperationContext._from_start_operation_context( - ctx - ) + start_ctx = TemporalStartOperationContext._from_start_operation_context(ctx) result = await self.start_operation(start_ctx, nexus_client, input) return result._to_nexus_result() @@ -185,9 +183,7 @@ async def cancel(self, ctx: CancelOperationContext, token: str) -> None: type=HandlerErrorType.INTERNAL, ) from err - cancel_ctx = TemporalNexusCancelOperationContext._from_cancel_operation_context( - ctx - ) + cancel_ctx = TemporalCancelOperationContext._from_cancel_operation_context(ctx) match operation_token.type: case OperationTokenType.WORKFLOW: options = CancelWorkflowRunOptions( @@ -197,7 +193,7 @@ async def cancel(self, ctx: CancelOperationContext, token: str) -> None: async def cancel_workflow_run( self, - ctx: TemporalNexusCancelOperationContext, # pyright: ignore[reportUnusedParameter] + ctx: TemporalCancelOperationContext, # pyright: ignore[reportUnusedParameter] options: CancelWorkflowRunOptions, ) -> None: """Cancels the workflow backing the Nexus operation. diff --git a/temporalio/nexus/_util.py b/temporalio/nexus/_util.py index 66d8c069c..f129dda2b 100644 --- a/temporalio/nexus/_util.py +++ b/temporalio/nexus/_util.py @@ -16,7 +16,7 @@ ) from temporalio.nexus._operation_context import ( - TemporalNexusStartOperationContext, + TemporalStartOperationContext, WorkflowRunOperationContext, ) from temporalio.nexus._temporal_client import ( @@ -55,7 +55,7 @@ def get_temporal_operation_start_method_input_and_output_type_annotations( start: Callable[ [ NexusServiceType, - TemporalNexusStartOperationContext, + TemporalStartOperationContext, TemporalNexusClient, InputT, ], @@ -73,7 +73,7 @@ def get_temporal_operation_start_method_input_and_output_type_annotations( return _get_wrapped_start_method_input_and_output_type_annotations( start, expected_param_types=( - TemporalNexusStartOperationContext, + TemporalStartOperationContext, TemporalNexusClient, ), expected_return_origin=TemporalOperationResult, diff --git a/temporalio/workflow/_nexus.py b/temporalio/workflow/_nexus.py index b8c8e88a1..29bd10715 100644 --- a/temporalio/workflow/_nexus.py +++ b/temporalio/workflow/_nexus.py @@ -218,7 +218,7 @@ async def start_operation( operation: Callable[ [ NexusServiceType, - temporalio.nexus.TemporalNexusStartOperationContext, + temporalio.nexus.TemporalStartOperationContext, temporalio.nexus.TemporalNexusClient, InputT, ], @@ -390,7 +390,7 @@ async def execute_operation( operation: Callable[ [ NexusServiceType, - temporalio.nexus.TemporalNexusStartOperationContext, + temporalio.nexus.TemporalStartOperationContext, temporalio.nexus.TemporalNexusClient, InputT, ], diff --git a/tests/nexus/test_handler_operation_definitions.py b/tests/nexus/test_handler_operation_definitions.py index 4a6e644b9..f47e3f47f 100644 --- a/tests/nexus/test_handler_operation_definitions.py +++ b/tests/nexus/test_handler_operation_definitions.py @@ -112,10 +112,10 @@ def test_unsafe_narrow_context_annotations_warn_and_drop_input_type(): with pytest.warns( UserWarning, - match="Expected parameter 1 .* TemporalNexusStartOperationContext", + match="Expected parameter 1 .* TemporalStartOperationContext", ): - class MyTemporalOpCtx(nexus.TemporalNexusStartOperationContext): + class MyTemporalOpCtx(nexus.TemporalStartOperationContext): def custom_method(self): raise NotImplementedError diff --git a/tests/nexus/test_nexus_type_errors.py b/tests/nexus/test_nexus_type_errors.py index ffdb60c65..1486f9791 100644 --- a/tests/nexus/test_nexus_type_errors.py +++ b/tests/nexus/test_nexus_type_errors.py @@ -13,7 +13,7 @@ import temporalio.nexus from temporalio import workflow from temporalio.client import Client, NexusOperationHandle -from temporalio.nexus import TemporalNexusOperationStartHandlerFunc +from temporalio.nexus import TemporalOperationStartHandlerFunc from temporalio.service import ServiceClient @@ -100,7 +100,7 @@ async def my_workflow_run_operation( @temporalio.nexus.temporal_operation async def my_temporal_operation( self, - _ctx: temporalio.nexus.TemporalNexusStartOperationContext, + _ctx: temporalio.nexus.TemporalStartOperationContext, client: temporalio.nexus.TemporalNexusClient, input: int, ) -> temporalio.nexus.TemporalOperationResult[None]: @@ -180,7 +180,7 @@ async def my_workflow_run_operation( @temporalio.nexus.temporal_operation async def my_temporal_operation( self, - _ctx: temporalio.nexus.TemporalNexusStartOperationContext, + _ctx: temporalio.nexus.TemporalStartOperationContext, _client: temporalio.nexus.TemporalNexusClient, _input: int, ) -> temporalio.nexus.TemporalOperationResult[None]: @@ -204,26 +204,26 @@ async def my_workflow_run_operation( @temporalio.nexus.temporal_operation async def my_temporal_operation( self, - _ctx: temporalio.nexus.TemporalNexusStartOperationContext, + _ctx: temporalio.nexus.TemporalStartOperationContext, _client: temporalio.nexus.TemporalNexusClient, _input: int, ) -> temporalio.nexus.TemporalOperationResult[None]: raise NotImplementedError -_handler: TemporalNexusOperationStartHandlerFunc[ +_handler: TemporalOperationStartHandlerFunc[ MyServiceHandler, int, None, ] = MyServiceHandler.my_temporal_operation -_BadHandler: TypeAlias = temporalio.nexus.TemporalNexusOperationStartHandlerFunc[ +_BadHandler: TypeAlias = temporalio.nexus.TemporalOperationStartHandlerFunc[ MyServiceHandler, str, None, ] -_bad_handler: TemporalNexusOperationStartHandlerFunc[ +_bad_handler: TemporalOperationStartHandlerFunc[ MyServiceHandler, str, None, @@ -235,7 +235,7 @@ class MyUnsafeContextAnnotationServiceHandler: # A temporal operation receives TemporalStartOperationContext at runtime, so # requiring an arbitrary user subclass is not safe. class MyCustomTemporalStartOperationContext( - temporalio.nexus.TemporalNexusStartOperationContext + temporalio.nexus.TemporalStartOperationContext ): def custom_state(self) -> str: raise NotImplementedError diff --git a/tests/nexus/test_temporal_operation.py b/tests/nexus/test_temporal_operation.py index 8bdfa267e..c101ede3b 100644 --- a/tests/nexus/test_temporal_operation.py +++ b/tests/nexus/test_temporal_operation.py @@ -75,7 +75,7 @@ def __init__(self) -> None: @nexus.temporal_operation async def echo( self, - _ctx: nexus.TemporalNexusStartOperationContext, + _ctx: nexus.TemporalStartOperationContext, client: nexus.TemporalNexusClient, input: Input, ) -> nexus.TemporalOperationResult[str]: @@ -86,7 +86,7 @@ async def echo( @nexus.temporal_operation async def blocking( self, - _ctx: nexus.TemporalNexusStartOperationContext, + _ctx: nexus.TemporalStartOperationContext, client: nexus.TemporalNexusClient, _input: None, ) -> nexus.TemporalOperationResult[None]: @@ -97,7 +97,7 @@ async def blocking( @nexus.temporal_operation async def double_start( self, - _ctx: nexus.TemporalNexusStartOperationContext, + _ctx: nexus.TemporalStartOperationContext, client: nexus.TemporalNexusClient, input: Input, ) -> nexus.TemporalOperationResult[None]: @@ -112,7 +112,7 @@ async def double_start( @nexus.temporal_operation async def concurrent_start( self, - _ctx: nexus.TemporalNexusStartOperationContext, + _ctx: nexus.TemporalStartOperationContext, client: nexus.TemporalNexusClient, input: Input, ) -> nexus.TemporalOperationResult[str]: @@ -157,7 +157,7 @@ async def concurrent_start( @nexus.temporal_operation async def retry_after_failed_start( self, - _ctx: nexus.TemporalNexusStartOperationContext, + _ctx: nexus.TemporalStartOperationContext, client: nexus.TemporalNexusClient, input: Input, ) -> nexus.TemporalOperationResult[str]: @@ -179,23 +179,21 @@ async def retry_after_failed_start( @nexus.temporal_operation async def sync_result( self, - _ctx: nexus.TemporalNexusStartOperationContext, + _ctx: nexus.TemporalStartOperationContext, _client: nexus.TemporalNexusClient, input: Input, ) -> nexus.TemporalOperationResult[str]: return nexus.TemporalOperationResult.sync(input.value) @operation_handler - def custom_cancel(self) -> nexus.TemporalNexusOperationHandler[str, None]: + def custom_cancel(self) -> nexus.TemporalOperationHandler[str, None]: event = self.started_custom_cancel_workflow - class CustomCancelNexusOpHandler( - nexus.TemporalNexusOperationHandler[str, None] - ): + class CustomCancelNexusOpHandler(nexus.TemporalOperationHandler[str, None]): @override async def start_operation( self, - ctx: nexus.TemporalNexusStartOperationContext, + ctx: nexus.TemporalStartOperationContext, client: nexus.TemporalNexusClient, input: str, ) -> nexus.TemporalOperationResult[None]: @@ -206,7 +204,7 @@ async def start_operation( @override async def cancel_workflow_run( self, - ctx: nexus.TemporalNexusCancelOperationContext, + ctx: nexus.TemporalCancelOperationContext, options: nexus.CancelWorkflowRunOptions, ): # get a handle to the workflow @@ -551,7 +549,7 @@ class TemporalOperationOverloadTestServiceHandler: @nexus.temporal_operation async def no_param( self, - _ctx: nexus.TemporalNexusStartOperationContext, + _ctx: nexus.TemporalStartOperationContext, client: nexus.TemporalNexusClient, _input: TemporalOperationOverloadTestValue, ) -> nexus.TemporalOperationResult[TemporalOperationOverloadTestValue]: @@ -563,7 +561,7 @@ async def no_param( @nexus.temporal_operation async def single_param( self, - _ctx: nexus.TemporalNexusStartOperationContext, + _ctx: nexus.TemporalStartOperationContext, client: nexus.TemporalNexusClient, input: TemporalOperationOverloadTestValue, ) -> nexus.TemporalOperationResult[TemporalOperationOverloadTestValue]: @@ -576,7 +574,7 @@ async def single_param( @nexus.temporal_operation async def multi_param( self, - _ctx: nexus.TemporalNexusStartOperationContext, + _ctx: nexus.TemporalStartOperationContext, client: nexus.TemporalNexusClient, input: TemporalOperationOverloadTestValue, ) -> nexus.TemporalOperationResult[TemporalOperationOverloadTestValue]: @@ -589,7 +587,7 @@ async def multi_param( @nexus.temporal_operation async def by_name( self, - _ctx: nexus.TemporalNexusStartOperationContext, + _ctx: nexus.TemporalStartOperationContext, client: nexus.TemporalNexusClient, input: TemporalOperationOverloadTestValue, ) -> nexus.TemporalOperationResult[TemporalOperationOverloadTestValue]: @@ -603,7 +601,7 @@ async def by_name( @nexus.temporal_operation async def by_name_multi_param( self, - _ctx: nexus.TemporalNexusStartOperationContext, + _ctx: nexus.TemporalStartOperationContext, client: nexus.TemporalNexusClient, input: TemporalOperationOverloadTestValue, ) -> nexus.TemporalOperationResult[TemporalOperationOverloadTestValue]: