Skip to content

Commit f8077c5

Browse files
committed
Respond to upstream: sync_operation_handler
1 parent 320e1f1 commit f8077c5

File tree

4 files changed

+168
-247
lines changed

4 files changed

+168
-247
lines changed

tests/nexus/test_dynamic_creation_of_user_handler_classes.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import uuid
2-
from typing import Any
32

43
import httpx
54
import nexusrpc.handler
65
import pytest
7-
from nexusrpc.handler import SyncOperationHandler
6+
from nexusrpc.handler import sync_operation_handler
7+
from nexusrpc.handler._util import get_operation_factory
88

99
from temporalio.client import Client
1010
from temporalio.worker import Worker
@@ -33,22 +33,19 @@ def make_incrementer_user_service_definition_and_service_handler_classes(
3333
#
3434
# service handler
3535
#
36-
def factory(self: Any) -> nexusrpc.handler.OperationHandler[int, int]:
37-
async def _increment_op(
38-
ctx: nexusrpc.handler.StartOperationContext,
39-
input: int,
40-
) -> int:
41-
return input + 1
42-
43-
return SyncOperationHandler.from_callable(_increment_op)
44-
45-
op_handler_factories = {
46-
# TODO(nexus-prerelease): check that name=name should be required here. Should the op factory
47-
# name not default to the name of the method attribute (i.e. key), as opposed to
48-
# the name of the method object (i.e. value.__name__)?
49-
name: nexusrpc.handler.operation_handler(name=name)(factory)
50-
for name in op_names
51-
}
36+
@sync_operation_handler
37+
async def _increment_op(
38+
self,
39+
ctx: nexusrpc.handler.StartOperationContext,
40+
input: int,
41+
) -> int:
42+
return input + 1
43+
44+
op_handler_factories = {}
45+
for name in op_names:
46+
op_handler_factory, _ = get_operation_factory(_increment_op)
47+
assert op_handler_factory
48+
op_handler_factories[name] = op_handler_factory
5249

5350
handler_cls = nexusrpc.handler.service_handler(service=service_cls)(
5451
type("ServiceImpl", (), op_handler_factories)

0 commit comments

Comments
 (0)