Skip to content

Commit 4e6666f

Browse files
committed
Remove top-level aliases
1 parent e6c4693 commit 4e6666f

8 files changed

Lines changed: 139 additions & 133 deletions

File tree

temporalio/nexus/handler.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -56,28 +56,28 @@
5656
# TODO(dan): confirm approach here: Temporal Nexus services will use this instead of
5757
# nexusrpc.handler.Operation in order to avoid having to implement fetch_info and
5858
# fetch_result.
59-
class Operation(nexusrpc.OperationHandler[I, O]):
59+
class Operation(nexusrpc.handler.OperationHandler[I, O]):
6060
"""
6161
Interface that must be implemented by an operation in a Temporal Nexus service.
6262
"""
6363

6464
# fetch_info and fetch_result are not currently to be implemented by Temporal Nexus services.
6565

6666
async def fetch_info(
67-
self, token: str, ctx: nexusrpc.FetchOperationInfoContext
68-
) -> nexusrpc.OperationInfo:
67+
self, token: str, ctx: nexusrpc.handler.FetchOperationInfoContext
68+
) -> nexusrpc.handler.OperationInfo:
6969
raise NotImplementedError
7070

7171
async def fetch_result(
72-
self, token: str, ctx: nexusrpc.FetchOperationResultContext
72+
self, token: str, ctx: nexusrpc.handler.FetchOperationResultContext
7373
) -> O:
7474
raise NotImplementedError
7575

7676

7777
# TODO(dan): naming, visibility, make this less awkward
7878
def get_input_and_output_types_from_workflow_run_start_method(
7979
start_method: Callable[
80-
[S, nexusrpc.StartOperationContext, I],
80+
[S, nexusrpc.handler.StartOperationContext, I],
8181
Awaitable[WorkflowHandle[Any, O]],
8282
],
8383
) -> tuple[
@@ -120,7 +120,7 @@ def get_input_and_output_types_from_workflow_run_start_method(
120120
# No-param overload
121121
@overload
122122
async def start_workflow(
123-
ctx: nexusrpc.StartOperationContext,
123+
ctx: nexusrpc.handler.StartOperationContext,
124124
workflow: MethodAsyncNoParam[SelfType, ReturnType],
125125
*,
126126
id: str,
@@ -132,7 +132,7 @@ async def start_workflow(
132132
# Single-param overload
133133
@overload
134134
async def start_workflow(
135-
ctx: nexusrpc.StartOperationContext,
135+
ctx: nexusrpc.handler.StartOperationContext,
136136
workflow: MethodAsyncSingleParam[SelfType, ParamType, ReturnType],
137137
arg: ParamType,
138138
*,
@@ -145,7 +145,7 @@ async def start_workflow(
145145
# Multiple-params overload
146146
@overload
147147
async def start_workflow(
148-
ctx: nexusrpc.StartOperationContext,
148+
ctx: nexusrpc.handler.StartOperationContext,
149149
workflow: Callable[Concatenate[SelfType, MultiParamSpec], Awaitable[ReturnType]],
150150
*,
151151
args: Sequence[Any],
@@ -159,7 +159,7 @@ async def start_workflow(
159159

160160

161161
async def start_workflow(
162-
ctx: nexusrpc.StartOperationContext,
162+
ctx: nexusrpc.handler.StartOperationContext,
163163
workflow: Callable[..., Awaitable[Any]],
164164
arg: Any = temporalio.common._arg_unset,
165165
*,
@@ -268,11 +268,11 @@ async def start_workflow(
268268
# TODO(dan): Not for merge: this is not required for Temporal Nexus, but implementing in
269269
# order to check that the design extends well to this.
270270
async def fetch_workflow_info(
271-
ctx: nexusrpc.FetchOperationInfoContext,
271+
ctx: nexusrpc.handler.FetchOperationInfoContext,
272272
token: str,
273-
) -> nexusrpc.OperationInfo:
273+
) -> nexusrpc.handler.OperationInfo:
274274
# TODO(dan)
275-
return nexusrpc.OperationInfo(
275+
return nexusrpc.handler.OperationInfo(
276276
token=token,
277277
status=nexusrpc.handler.OperationState.RUNNING,
278278
)
@@ -281,7 +281,7 @@ async def fetch_workflow_info(
281281
# TODO(dan): Not for merge: this is not required for Temporal Nexus, but implementing temporarily in
282282
# order to check that the design extends well to this.
283283
async def fetch_workflow_result(
284-
ctx: nexusrpc.FetchOperationResultContext,
284+
ctx: nexusrpc.handler.FetchOperationResultContext,
285285
token: str,
286286
client: Optional[Client] = None,
287287
) -> Any:
@@ -292,7 +292,7 @@ async def fetch_workflow_result(
292292

293293

294294
async def cancel_workflow(
295-
ctx: nexusrpc.CancelOperationContext,
295+
ctx: nexusrpc.handler.CancelOperationContext,
296296
token: str,
297297
client: Optional[Client] = None,
298298
) -> None:
@@ -330,12 +330,12 @@ def get_task_queue() -> str:
330330
return context.task_queue
331331

332332

333-
class WorkflowRunOperation(nexusrpc.OperationHandler[I, O], Generic[I, O, S]):
333+
class WorkflowRunOperation(nexusrpc.handler.OperationHandler[I, O], Generic[I, O, S]):
334334
def __init__(
335335
self,
336336
service: S,
337337
start_method: Callable[
338-
[S, nexusrpc.StartOperationContext, I],
338+
[S, nexusrpc.handler.StartOperationContext, I],
339339
Awaitable[WorkflowHandle[Any, O]],
340340
],
341341
output_type: Optional[Type] = None,
@@ -346,16 +346,16 @@ def __init__(
346346
# TODO(dan): What is @wraps doing exactly?
347347
@wraps(start_method)
348348
async def start(
349-
self, ctx: nexusrpc.StartOperationContext, input: I
350-
) -> nexusrpc.StartOperationResultAsync:
349+
self, ctx: nexusrpc.handler.StartOperationContext, input: I
350+
) -> nexusrpc.handler.StartOperationResultAsync:
351351
wf_handle = await start_method(service, ctx, input)
352352
token = WorkflowOperationToken.from_workflow_handle(wf_handle).encode()
353-
return nexusrpc.StartOperationResultAsync(token)
353+
return nexusrpc.handler.StartOperationResultAsync(token)
354354

355355
# TODO(dan): get rid of first parameter?
356356
# TODO(dan): remove before merge; implementing temporarily to check that design extends well to this
357357
async def fetch_result(
358-
self, ctx: nexusrpc.FetchOperationResultContext, token: str
358+
self, ctx: nexusrpc.handler.FetchOperationResultContext, token: str
359359
) -> O:
360360
return await fetch_workflow_result(ctx, token)
361361

@@ -365,13 +365,13 @@ async def fetch_result(
365365
self.start = types.MethodType(start, self)
366366
self.fetch_result = types.MethodType(fetch_result, self)
367367

368-
async def cancel(self, ctx: nexusrpc.CancelOperationContext, token: str) -> None:
368+
async def cancel(self, ctx: nexusrpc.handler.CancelOperationContext, token: str) -> None:
369369
await cancel_workflow(ctx, token)
370370

371371
# TODO(dan): remove before merge; implementing temporarily to check that design extends well to this
372372
async def fetch_info(
373-
self, ctx: nexusrpc.FetchOperationInfoContext, token: str
374-
) -> nexusrpc.OperationInfo:
373+
self, ctx: nexusrpc.handler.FetchOperationInfoContext, token: str
374+
) -> nexusrpc.handler.OperationInfo:
375375
return await fetch_workflow_info(ctx, token)
376376

377377

@@ -381,7 +381,7 @@ async def fetch_info(
381381
def workflow_run_operation(
382382
start_method: Optional[
383383
Callable[
384-
[S, nexusrpc.StartOperationContext, I],
384+
[S, nexusrpc.handler.StartOperationContext, I],
385385
Awaitable[WorkflowHandle[Any, O]],
386386
]
387387
] = None,
@@ -392,7 +392,7 @@ def workflow_run_operation(
392392
Callable[
393393
[
394394
Callable[
395-
[S, nexusrpc.StartOperationContext, I],
395+
[S, nexusrpc.handler.StartOperationContext, I],
396396
Awaitable[WorkflowHandle[Any, O]],
397397
]
398398
],
@@ -401,7 +401,7 @@ def workflow_run_operation(
401401
]:
402402
def decorator(
403403
start_method: Callable[
404-
[S, nexusrpc.StartOperationContext, I],
404+
[S, nexusrpc.handler.StartOperationContext, I],
405405
Awaitable[WorkflowHandle[Any, O]],
406406
],
407407
) -> Callable[[S], WorkflowRunOperation[I, O, S]]:

temporalio/worker/_nexus.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,14 @@ async def run() -> temporalio.bridge.proto.nexus.NexusTaskCompletion:
233233
)
234234
)
235235
try:
236-
ctx = nexusrpc.StartOperationContext(
236+
ctx = nexusrpc.handler.StartOperationContext(
237237
service=start_request.service,
238238
operation=start_request.operation,
239239
headers=header,
240240
request_id=start_request.request_id,
241241
callback_url=start_request.callback,
242242
caller_links=[
243-
nexusrpc.Link(url=l.url, type=l.type)
243+
nexusrpc.handler.Link(url=l.url, type=l.type)
244244
for l in start_request.links
245245
],
246246
callback_header=dict(start_request.callback_header),
@@ -263,9 +263,9 @@ async def run() -> temporalio.bridge.proto.nexus.NexusTaskCompletion:
263263
),
264264
)
265265
except Exception as err:
266-
raise nexusrpc.HandlerError(
266+
raise nexusrpc.handler.HandlerError(
267267
"Data converter failed to decode Nexus operation input",
268-
type=nexusrpc.HandlerErrorType.BAD_REQUEST,
268+
type=nexusrpc.handler.HandlerErrorType.BAD_REQUEST,
269269
cause=err,
270270
retryable=False,
271271
) from err
@@ -283,7 +283,7 @@ async def run() -> temporalio.bridge.proto.nexus.NexusTaskCompletion:
283283
# temporary hack to allow developing type signatures that support
284284
# non-async start methods.
285285
result = operation_handler.start(ctx, input)
286-
except nexusrpc.OperationError as err:
286+
except nexusrpc.handler.OperationError as err:
287287
return temporalio.bridge.proto.nexus.NexusTaskCompletion(
288288
task_token=task_token,
289289
completed=temporalio.api.nexus.v1.Response(
@@ -309,7 +309,7 @@ async def run() -> temporalio.bridge.proto.nexus.NexusTaskCompletion:
309309
),
310310
)
311311
else:
312-
if isinstance(result, nexusrpc.StartOperationResultAsync):
312+
if isinstance(result, nexusrpc.handler.StartOperationResultAsync):
313313
op_resp = temporalio.api.nexus.v1.StartOperationResponse(
314314
async_success=temporalio.api.nexus.v1.StartOperationResponse.Async(
315315
operation_token=result.token,
@@ -319,7 +319,7 @@ async def run() -> temporalio.bridge.proto.nexus.NexusTaskCompletion:
319319
],
320320
)
321321
)
322-
elif isinstance(result, nexusrpc.StartOperationResultSync):
322+
elif isinstance(result, nexusrpc.handler.StartOperationResultSync):
323323
# TODO(dan): error handling here; what error type should it be?
324324
[payload] = await self._data_converter.encode([result.value])
325325
op_resp = temporalio.api.nexus.v1.StartOperationResponse(
@@ -331,8 +331,8 @@ async def run() -> temporalio.bridge.proto.nexus.NexusTaskCompletion:
331331
# TODO(dan): what should the error response be when the user has failed to wrap their return type?
332332
# TODO(dan): unify this failure completion with the path above
333333
err = TypeError(
334-
"Operation start method must return either nexusrpc.StartOperationResultSync "
335-
"or nexusrpc.StartOperationResultAsync"
334+
"Operation start method must return either nexusrpc.handler.StartOperationResultSync "
335+
"or nexusrpc.handler.StartOperationResultAsync"
336336
)
337337
handler_err = _exception_to_handler_error(err)
338338
return temporalio.bridge.proto.nexus.NexusTaskCompletion(
@@ -382,7 +382,7 @@ async def _handle_cancel_operation(
382382
operation=request.operation,
383383
)
384384
)
385-
ctx = nexusrpc.CancelOperationContext(
385+
ctx = nexusrpc.handler.CancelOperationContext(
386386
service=request.service,
387387
operation=request.operation,
388388
)
@@ -448,7 +448,7 @@ async def _exception_to_failure_proto(
448448

449449
async def _operation_error_to_proto(
450450
self,
451-
err: nexusrpc.OperationError,
451+
err: nexusrpc.handler.OperationError,
452452
) -> temporalio.api.nexus.v1.UnsuccessfulOperationError:
453453
cause = err.__cause__
454454
if cause is None:
@@ -459,7 +459,7 @@ async def _operation_error_to_proto(
459459
)
460460

461461
async def _handler_error_to_proto(
462-
self, err: nexusrpc.HandlerError
462+
self, err: nexusrpc.handler.HandlerError
463463
) -> temporalio.api.nexus.v1.HandlerError:
464464
# message HandlerError {
465465
# string error_type = 1;
@@ -479,40 +479,40 @@ async def _handler_error_to_proto(
479479

480480

481481
# TODO(dan): tests for this function
482-
def _exception_to_handler_error(err: BaseException) -> nexusrpc.HandlerError:
482+
def _exception_to_handler_error(err: BaseException) -> nexusrpc.handler.HandlerError:
483483
# Based on sdk-typescript's convertKnownErrors:
484484
# https://github.com/temporalio/sdk-typescript/blob/nexus/packages/worker/src/nexus.ts
485-
if isinstance(err, nexusrpc.HandlerError):
485+
if isinstance(err, nexusrpc.handler.HandlerError):
486486
print(f"🌈 retryable = {err.retryable}")
487487
return err
488488
elif isinstance(err, ApplicationError):
489-
return nexusrpc.HandlerError(
489+
return nexusrpc.handler.HandlerError(
490490
# TODO(dan): what should message be?
491491
err.message,
492-
type=nexusrpc.HandlerErrorType.INTERNAL,
492+
type=nexusrpc.handler.HandlerErrorType.INTERNAL,
493493
cause=err,
494494
# TODO(dan): is there a reason to support retryable=None?
495495
retryable=not err.non_retryable,
496496
)
497497
elif isinstance(err, RPCError):
498498
if err.status == RPCStatusCode.INVALID_ARGUMENT:
499-
return nexusrpc.HandlerError(
500-
err.message, type=nexusrpc.HandlerErrorType.BAD_REQUEST, cause=err
499+
return nexusrpc.handler.HandlerError(
500+
err.message, type=nexusrpc.handler.HandlerErrorType.BAD_REQUEST, cause=err
501501
)
502502
elif err.status in [
503503
RPCStatusCode.ALREADY_EXISTS,
504504
RPCStatusCode.FAILED_PRECONDITION,
505505
RPCStatusCode.OUT_OF_RANGE,
506506
]:
507-
return nexusrpc.HandlerError(
507+
return nexusrpc.handler.HandlerError(
508508
err.message,
509-
type=nexusrpc.HandlerErrorType.INTERNAL,
509+
type=nexusrpc.handler.HandlerErrorType.INTERNAL,
510510
cause=err,
511511
retryable=False,
512512
)
513513
elif err.status in [RPCStatusCode.ABORTED, RPCStatusCode.UNAVAILABLE]:
514-
return nexusrpc.HandlerError(
515-
err.message, type=nexusrpc.HandlerErrorType.UNAVAILABLE, cause=err
514+
return nexusrpc.handler.HandlerError(
515+
err.message, type=nexusrpc.handler.HandlerErrorType.UNAVAILABLE, cause=err
516516
)
517517
elif err.status in [
518518
RPCStatusCode.CANCELLED,
@@ -526,33 +526,33 @@ def _exception_to_handler_error(err: BaseException) -> nexusrpc.HandlerError:
526526
# we convert to internal because this is not a client auth error and happens
527527
# when the handler fails to auth with Temporal and should be considered
528528
# retryable.
529-
return nexusrpc.HandlerError(
530-
err.message, type=nexusrpc.HandlerErrorType.INTERNAL, cause=err
529+
return nexusrpc.handler.HandlerError(
530+
err.message, type=nexusrpc.handler.HandlerErrorType.INTERNAL, cause=err
531531
)
532532
elif err.status == RPCStatusCode.NOT_FOUND:
533-
return nexusrpc.HandlerError(
534-
err.message, type=nexusrpc.HandlerErrorType.NOT_FOUND, cause=err
533+
return nexusrpc.handler.HandlerError(
534+
err.message, type=nexusrpc.handler.HandlerErrorType.NOT_FOUND, cause=err
535535
)
536536
elif err.status == RPCStatusCode.RESOURCE_EXHAUSTED:
537-
return nexusrpc.HandlerError(
537+
return nexusrpc.handler.HandlerError(
538538
err.message,
539-
type=nexusrpc.HandlerErrorType.RESOURCE_EXHAUSTED,
539+
type=nexusrpc.handler.HandlerErrorType.RESOURCE_EXHAUSTED,
540540
cause=err,
541541
)
542542
elif err.status == RPCStatusCode.UNIMPLEMENTED:
543-
return nexusrpc.HandlerError(
544-
err.message, type=nexusrpc.HandlerErrorType.NOT_IMPLEMENTED, cause=err
543+
return nexusrpc.handler.HandlerError(
544+
err.message, type=nexusrpc.handler.HandlerErrorType.NOT_IMPLEMENTED, cause=err
545545
)
546546
elif err.status == RPCStatusCode.DEADLINE_EXCEEDED:
547-
return nexusrpc.HandlerError(
548-
err.message, type=nexusrpc.HandlerErrorType.UPSTREAM_TIMEOUT, cause=err
547+
return nexusrpc.handler.HandlerError(
548+
err.message, type=nexusrpc.handler.HandlerErrorType.UPSTREAM_TIMEOUT, cause=err
549549
)
550550
else:
551-
return nexusrpc.HandlerError(
551+
return nexusrpc.handler.HandlerError(
552552
f"Unhandled RPC error status: {err.status}",
553-
type=nexusrpc.HandlerErrorType.INTERNAL,
553+
type=nexusrpc.handler.HandlerErrorType.INTERNAL,
554554
cause=err,
555555
)
556-
return nexusrpc.HandlerError(
557-
str(err), type=nexusrpc.HandlerErrorType.INTERNAL, cause=err
556+
return nexusrpc.handler.HandlerError(
557+
str(err), type=nexusrpc.handler.HandlerErrorType.INTERNAL, cause=err
558558
)

temporalio/worker/_worker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def __init__(
159159
:py:func:`@activity.defn<temporalio.activity.defn>`. Activities
160160
may be async functions or non-async functions.
161161
nexus_services: Nexus service instances decorated with
162-
:py:func:`@nexusrpc.service_handler<nexusrpc.service_handler>`.
162+
:py:func:`@nexusrpc.handler.service<nexusrpc.service>`.
163163
workflows: Workflow classes decorated with
164164
:py:func:`@workflow.defn<temporalio.workflow.defn>`.
165165
activity_executor: Concurrent executor to use for non-async

temporalio/workflow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5182,7 +5182,7 @@ def __init__(
51825182
else:
51835183
raise ValueError(
51845184
f"`service` may be a name (str), or a class decorated with either "
5185-
f"@nexusrpc.service_handler or @nexusrpc.contract.service. "
5185+
f"@nexusrpc.handler.service or @nexusrpc.contract.service. "
51865186
f"Invalid service type: {type(service)}"
51875187
)
51885188
print(f"🌈 NexusClient using service name: {self._service_name}")

0 commit comments

Comments
 (0)