Skip to content

Commit c073963

Browse files
committed
Format docstrings
1 parent 98d561d commit c073963

File tree

11 files changed

+60
-55
lines changed

11 files changed

+60
-55
lines changed

temporalio/exceptions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,8 @@ def __init__(
375375
operation: str,
376376
operation_token: str,
377377
):
378-
"""
378+
"""Initialize a Nexus operation error.
379+
379380
Args:
380381
message: The error message.
381382
scheduled_event_id: The NexusOperationScheduled event ID for the failed operation.

temporalio/nexus/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""Temporal Nexus support
2+
3+
See https://github.com/temporalio/sdk-python/tree/main#nexus
4+
"""
5+
16
from ._decorators import workflow_run_operation as workflow_run_operation
27
from ._operation_context import Info as Info
38
from ._operation_context import LoggerAdapter as LoggerAdapter

temporalio/nexus/_decorators.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ def workflow_run_operation(
9191
],
9292
],
9393
]:
94-
"""
95-
Decorator marking a method as the start method for a workflow-backed operation.
96-
"""
94+
"""Decorator marking a method as the start method for a workflow-backed operation."""
9795

9896
def decorator(
9997
start: Callable[

temporalio/nexus/_operation_context.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,17 @@ class Info:
6363

6464

6565
def in_operation() -> bool:
66-
"""
67-
Whether the current code is inside a Nexus operation.
68-
"""
66+
"""Whether the current code is inside a Nexus operation."""
6967
return _try_temporal_context() is not None
7068

7169

7270
def info() -> Info:
73-
"""
74-
Get the current Nexus operation information.
75-
"""
71+
"""Get the current Nexus operation information."""
7672
return _temporal_context().info()
7773

7874

7975
def client() -> temporalio.client.Client:
80-
"""
81-
Get the Temporal client used by the worker handling the current Nexus operation.
82-
"""
76+
"""Get the Temporal client used by the worker handling the current Nexus operation."""
8377
return _temporal_context().client
8478

8579

@@ -104,9 +98,7 @@ def _try_temporal_context() -> (
10498

10599
@dataclass
106100
class _TemporalStartOperationContext:
107-
"""
108-
Context for a Nexus start operation being handled by a Temporal Nexus Worker.
109-
"""
101+
"""Context for a Nexus start operation being handled by a Temporal Nexus Worker."""
110102

111103
nexus_context: StartOperationContext
112104
"""Nexus-specific start operation context."""
@@ -183,7 +175,10 @@ def _add_outbound_links(
183175

184176

185177
class WorkflowRunOperationContext(StartOperationContext):
178+
"""Context received by a workflow run operation."""
179+
186180
def __init__(self, *args, **kwargs):
181+
"""Initialize the workflow run operation context."""
187182
super().__init__(*args, **kwargs)
188183
self._temporal_context = _TemporalStartOperationContext.get()
189184

@@ -455,9 +450,7 @@ async def start_workflow(
455450

456451
@dataclass(frozen=True)
457452
class _TemporalCancelOperationContext:
458-
"""
459-
Context for a Nexus cancel operation being handled by a Temporal Nexus Worker.
460-
"""
453+
"""Context for a Nexus cancel operation being handled by a Temporal Nexus Worker."""
461454

462455
nexus_context: CancelOperationContext
463456
"""Nexus-specific cancel operation context."""
@@ -565,12 +558,16 @@ def _nexus_link_to_workflow_event(
565558

566559

567560
class LoggerAdapter(logging.LoggerAdapter):
561+
"""Logger adapter that adds Nexus operation context information."""
562+
568563
def __init__(self, logger: logging.Logger, extra: Optional[Mapping[str, Any]]):
564+
"""Initialize the logger adapter."""
569565
super().__init__(logger, extra or {})
570566

571567
def process(
572568
self, msg: Any, kwargs: MutableMapping[str, Any]
573569
) -> tuple[Any, MutableMapping[str, Any]]:
570+
"""Process log records to add Nexus operation context."""
574571
extra = dict(self.extra or {})
575572
if tctx := _try_temporal_context():
576573
extra["service"] = tctx.nexus_context.service

temporalio/nexus/_operation_handlers.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@
3636

3737

3838
class WorkflowRunOperationHandler(OperationHandler[InputT, OutputT]):
39-
"""
40-
Operation handler for Nexus operations that start a workflow.
39+
"""Operation handler for Nexus operations that start a workflow.
4140
4241
Use this class to create an operation handler that starts a workflow by passing your
4342
``start`` method to the constructor. Your ``start`` method must use
@@ -54,6 +53,7 @@ def __init__(
5453
input_type: Optional[Type[InputT]],
5554
output_type: Optional[Type[OutputT]],
5655
) -> None:
56+
"""Initialize the workflow run operation handler."""
5757
if not is_async_callable(start):
5858
raise RuntimeError(
5959
f"{start} is not an `async def` method. "
@@ -70,9 +70,7 @@ def __init__(
7070
async def start(
7171
self, ctx: StartOperationContext, input: InputT
7272
) -> StartOperationResultAsync:
73-
"""
74-
Start the operation, by starting a workflow and completing asynchronously.
75-
"""
73+
"""Start the operation, by starting a workflow and completing asynchronously."""
7674
handle = await self._start(ctx, input)
7775
if not isinstance(handle, WorkflowHandle):
7876
if isinstance(handle, client.WorkflowHandle):
@@ -94,13 +92,15 @@ async def cancel(self, ctx: CancelOperationContext, token: str) -> None:
9492
async def fetch_info(
9593
self, ctx: FetchOperationInfoContext, token: str
9694
) -> OperationInfo:
95+
"""Fetch operation info (not supported for Temporal Nexus operations)."""
9796
raise NotImplementedError(
9897
"Temporal Nexus operation handlers do not support fetching operation info."
9998
)
10099

101100
async def fetch_result(
102101
self, ctx: FetchOperationResultContext, token: str
103102
) -> OutputT:
103+
"""Fetch operation result (not supported for Temporal Nexus operations)."""
104104
raise NotImplementedError(
105105
"Temporal Nexus operation handlers do not support fetching the operation result."
106106
)
@@ -131,8 +131,7 @@ async def _cancel_workflow(
131131
token: str,
132132
**kwargs: Any,
133133
) -> None:
134-
"""
135-
Cancel a workflow that is backing a Nexus operation.
134+
"""Cancel a workflow that is backing a Nexus operation.
136135
137136
This function is used by the Nexus worker to cancel a workflow that is backing a
138137
Nexus operation, i.e. started by a

temporalio/nexus/_token.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515

1616
@dataclass(frozen=True)
1717
class WorkflowHandle(Generic[OutputT]):
18-
"""
19-
A handle to a workflow that is backing a Nexus operation.
20-
18+
"""A handle to a workflow that is backing a Nexus operation.
2119
2220
Do not instantiate this directly. Use
2321
:py:func:`temporalio.nexus.WorkflowRunOperationContext.start_workflow` to create a
@@ -59,6 +57,7 @@ def _unsafe_from_client_workflow_handle(
5957
)
6058

6159
def to_token(self) -> str:
60+
"""Convert handle to a base64url-encoded token string."""
6261
return _base64url_encode_no_padding(
6362
json.dumps(
6463
{

temporalio/nexus/_util.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ def get_workflow_run_start_method_input_and_output_type_annotations(
4242
`start` must be a type-annotated start method that returns a
4343
:py:class:`temporalio.nexus.WorkflowHandle`.
4444
"""
45-
4645
input_type, output_type = _get_start_method_input_and_output_type_annotations(start)
4746
origin_type = typing.get_origin(output_type)
4847
if not origin_type:
@@ -107,6 +106,7 @@ def _get_start_method_input_and_output_type_annotations(
107106

108107

109108
def get_callable_name(fn: Callable[..., Any]) -> str:
109+
"""Return the name of a callable object."""
110110
method_name = getattr(fn, "__name__", None)
111111
if not method_name and callable(fn) and hasattr(fn, "__call__"):
112112
method_name = fn.__class__.__name__
@@ -158,8 +158,7 @@ def set_operation_factory(
158158
#
159159
# This file is licensed under the MIT License.
160160
def is_async_callable(obj: Any) -> bool:
161-
"""
162-
Return True if `obj` is an async callable.
161+
"""Return True if `obj` is an async callable.
163162
164163
Supports partials of async callable class instances.
165164
"""

temporalio/worker/_interceptor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ class StartNexusOperationInput(Generic[InputT, OutputT]):
302302
output_type: Optional[Type[OutputT]] = None
303303

304304
def __post_init__(self) -> None:
305+
"""Initialize operation-specific attributes after dataclass creation."""
305306
if isinstance(self.operation, nexusrpc.Operation):
306307
self.output_type = self.operation.output_type
307308
elif callable(self.operation):
@@ -319,6 +320,7 @@ def __post_init__(self) -> None:
319320

320321
@property
321322
def operation_name(self) -> str:
323+
"""Get the name of the Nexus operation."""
322324
if isinstance(self.operation, nexusrpc.Operation):
323325
return self.operation.name
324326
elif isinstance(self.operation, str):

temporalio/worker/_nexus.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ def __init__(
6969
self._fail_worker_exception_queue: asyncio.Queue[Exception] = asyncio.Queue()
7070

7171
async def run(self) -> None:
72-
"""
73-
Continually poll for Nexus tasks and dispatch to handlers.
74-
"""
72+
"""Continually poll for Nexus tasks and dispatch to handlers."""
7573

7674
async def raise_from_exception_queue() -> NoReturn:
7775
raise await self._fail_worker_exception_queue.get()
@@ -160,8 +158,7 @@ async def _handle_cancel_operation_task(
160158
request: temporalio.api.nexus.v1.CancelOperationRequest,
161159
headers: Mapping[str, str],
162160
) -> None:
163-
"""
164-
Handle a cancel operation task.
161+
"""Handle a cancel operation task.
165162
166163
Attempt to execute the user cancel_operation method. Handle errors and send the
167164
task completion.
@@ -213,13 +210,11 @@ async def _handle_start_operation_task(
213210
start_request: temporalio.api.nexus.v1.StartOperationRequest,
214211
headers: Mapping[str, str],
215212
) -> None:
216-
"""
217-
Handle a start operation task.
213+
"""Handle a start operation task.
218214
219215
Attempt to execute the user start_operation method and invoke the data converter
220216
on the result. Handle errors and send the task completion.
221217
"""
222-
223218
try:
224219
try:
225220
start_response = await self._start_operation(start_request, headers)
@@ -256,8 +251,7 @@ async def _start_operation(
256251
start_request: temporalio.api.nexus.v1.StartOperationRequest,
257252
headers: Mapping[str, str],
258253
) -> temporalio.api.nexus.v1.StartOperationResponse:
259-
"""
260-
Invoke the Nexus handler's start_operation method and construct the StartOperationResponse.
254+
"""Invoke the Nexus handler's start_operation method and construct the StartOperationResponse.
261255
262256
OperationError is handled by this function, since it results in a StartOperationResponse.
263257
@@ -326,8 +320,7 @@ async def _nexus_error_to_nexus_failure_proto(
326320
self,
327321
error: Union[nexusrpc.HandlerError, nexusrpc.OperationError],
328322
) -> temporalio.api.nexus.v1.Failure:
329-
"""
330-
Serialize ``error`` as a Nexus Failure proto.
323+
"""Serialize ``error`` as a Nexus Failure proto.
331324
332325
The Nexus Failure represents the top-level error. If there is a cause chain
333326
attached to the exception, then serialize it as the ``details``.
@@ -381,9 +374,7 @@ async def _operation_error_to_proto(
381374
async def _handler_error_to_proto(
382375
self, handler_error: nexusrpc.HandlerError
383376
) -> temporalio.api.nexus.v1.HandlerError:
384-
"""
385-
Serialize ``handler_error`` as a Nexus HandlerError proto.
386-
"""
377+
"""Serialize ``handler_error`` as a Nexus HandlerError proto."""
387378
retry_behavior = (
388379
temporalio.api.enums.v1.NexusHandlerErrorRetryBehavior.NEXUS_HANDLER_ERROR_RETRY_BEHAVIOR_RETRYABLE
389380
if handler_error.retryable_override is True

temporalio/worker/_worker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def __init__(
183183
otherwise. The default one will be properly shutdown, but if one
184184
is provided, the caller is responsible for shutting it down after
185185
the worker is shut down.
186-
nexus_operation_executor: Executor to use for non-async
186+
nexus_task_executor: Executor to use for non-async
187187
Nexus operations. This is required if any operation start methods
188188
are non-`async def`. :py:class:`concurrent.futures.ThreadPoolExecutor`
189189
is recommended.

0 commit comments

Comments
 (0)