Skip to content

Commit 1bcbb79

Browse files
committed
Use getters/setters
1 parent 38e2056 commit 1bcbb79

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

temporalio/nexus/_decorators.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from temporalio.nexus._util import (
2929
get_callable_name,
3030
get_workflow_run_start_method_input_and_output_type_annotations,
31+
set_operation_factory,
3132
)
3233

3334
ServiceHandlerT = TypeVar("ServiceHandlerT")
@@ -124,15 +125,17 @@ async def _start(
124125
return WorkflowRunOperationHandler(_start, input_type, output_type)
125126

126127
method_name = get_callable_name(start)
127-
# TODO(nexus-preview): make double-underscore attrs private to nexusrpc and expose getters/setters
128-
operation_handler_factory.__nexus_operation__ = nexusrpc.Operation(
129-
name=name or method_name,
130-
method_name=method_name,
131-
input_type=input_type,
132-
output_type=output_type,
128+
nexusrpc.set_operation_definition(
129+
operation_handler_factory,
130+
nexusrpc.Operation(
131+
name=name or method_name,
132+
method_name=method_name,
133+
input_type=input_type,
134+
output_type=output_type,
135+
),
133136
)
134137

135-
start.__nexus_operation_factory__ = operation_handler_factory
138+
set_operation_factory(start, operation_handler_factory)
136139
return start
137140

138141
if start is None:

temporalio/nexus/_util.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
Union,
1515
)
1616

17+
import nexusrpc
1718
from nexusrpc import (
1819
InputT,
1920
OutputT,
@@ -129,19 +130,19 @@ def get_callable_name(fn: Callable[..., Any]) -> str:
129130
def get_operation_factory(
130131
obj: Any,
131132
) -> tuple[
132-
Optional[Callable[[Any], OperationHandler[InputT, OutputT]]],
133-
Optional[nexusrpc.Operation[InputT, OutputT]],
133+
Optional[Callable[[Any], Any]],
134+
Optional[nexusrpc.Operation[Any, Any]],
134135
]:
135136
"""Return the :py:class:`Operation` for the object along with the factory function.
136137
137138
``obj`` should be a decorated operation start method.
138139
"""
139-
op_defn = get_operation_definition(obj)
140+
op_defn = nexusrpc.get_operation_definition(obj)
140141
if op_defn:
141142
factory = obj
142143
else:
143144
if factory := getattr(obj, "__nexus_operation_factory__", None):
144-
op_defn = get_operation_definition(factory)
145+
op_defn = nexusrpc.get_operation_definition(factory)
145146
if not isinstance(op_defn, nexusrpc.Operation):
146147
return None, None
147148
return factory, op_defn
@@ -150,7 +151,7 @@ def get_operation_factory(
150151
# TODO(nexus-preview) Copied from nexusrpc
151152
def set_operation_factory(
152153
obj: Any,
153-
operation_factory: Callable[[Any], OperationHandler[InputT, OutputT]],
154+
operation_factory: Callable[[Any], Any],
154155
) -> None:
155156
"""Set the :py:class:`OperationHandler` factory for this object.
156157

0 commit comments

Comments
 (0)