Skip to content

Commit 208989d

Browse files
committed
Eliminate unnecessary modeling of callable types
1 parent 5b821a2 commit 208989d

File tree

3 files changed

+10
-102
lines changed

3 files changed

+10
-102
lines changed

temporalio/worker/_interceptor.py

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import temporalio.common
3030
import temporalio.nexus
3131
import temporalio.workflow
32-
from temporalio.nexus import WorkflowRunOperationContext
3332
from temporalio.workflow import VersioningIntent
3433

3534

@@ -298,22 +297,7 @@ class StartNexusOperationInput(Generic[InputT, OutputT]):
298297

299298
endpoint: str
300299
service: str
301-
operation: Union[
302-
nexusrpc.Operation[InputT, OutputT],
303-
Callable[[Any], nexusrpc.handler.OperationHandler[InputT, OutputT]],
304-
Callable[
305-
[
306-
Any,
307-
Union[
308-
nexusrpc.handler.StartOperationContext,
309-
WorkflowRunOperationContext,
310-
],
311-
InputT,
312-
],
313-
Awaitable[temporalio.nexus.WorkflowHandle[OutputT]],
314-
],
315-
str,
316-
]
300+
operation: Union[nexusrpc.Operation[InputT, OutputT], str, Callable[..., Any]]
317301
input: InputT
318302
schedule_to_close_timeout: Optional[timedelta]
319303
headers: Optional[Mapping[str, str]]
@@ -324,13 +308,13 @@ class StartNexusOperationInput(Generic[InputT, OutputT]):
324308

325309
# TODO(nexus-prerelease): update this logic to handle service impl start methods
326310
def __post_init__(self) -> None:
327-
if isinstance(self.operation, str):
328-
self._operation_name = self.operation
329-
self._input_type = None
330-
elif isinstance(self.operation, nexusrpc.Operation):
311+
if isinstance(self.operation, nexusrpc.Operation):
331312
self._operation_name = self.operation.name
332313
self._input_type = self.operation.input_type
333314
self.output_type = self.operation.output_type
315+
elif isinstance(self.operation, str):
316+
self._operation_name = self.operation
317+
self._input_type = None
334318
elif isinstance(self.operation, Callable):
335319
_, op = nexusrpc.handler.get_operation_factory(self.operation)
336320
if isinstance(op, nexusrpc.Operation):

temporalio/worker/_workflow_instance.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
import temporalio.exceptions
6262
import temporalio.nexus
6363
import temporalio.workflow
64-
from temporalio.nexus import WorkflowRunOperationContext
6564
from temporalio.service import __version__
6665

6766
from ._interceptor import (
@@ -1499,22 +1498,7 @@ async def workflow_start_nexus_operation(
14991498
self,
15001499
endpoint: str,
15011500
service: str,
1502-
operation: Union[
1503-
nexusrpc.Operation[I, O],
1504-
Callable[[Any], nexusrpc.handler.OperationHandler[I, O]],
1505-
Callable[
1506-
[
1507-
Any,
1508-
Union[
1509-
nexusrpc.handler.StartOperationContext,
1510-
WorkflowRunOperationContext,
1511-
],
1512-
I,
1513-
],
1514-
Awaitable[temporalio.nexus.WorkflowHandle[O]],
1515-
],
1516-
str,
1517-
],
1501+
operation: Union[nexusrpc.Operation[I, O], str, Callable[..., Any]],
15181502
input: Any,
15191503
output_type: Optional[Type[O]] = None,
15201504
schedule_to_close_timeout: Optional[timedelta] = None,

temporalio/workflow.py

Lines changed: 4 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
import temporalio.exceptions
5959
import temporalio.nexus
6060
import temporalio.workflow
61-
from temporalio.nexus import WorkflowRunOperationContext
6261

6362
from .types import (
6463
AnyType,
@@ -855,22 +854,7 @@ async def workflow_start_nexus_operation(
855854
self,
856855
endpoint: str,
857856
service: str,
858-
operation: Union[
859-
nexusrpc.Operation[I, O],
860-
Callable[[Any], nexusrpc.handler.OperationHandler[I, O]],
861-
Callable[
862-
[
863-
S,
864-
Union[
865-
nexusrpc.handler.StartOperationContext,
866-
WorkflowRunOperationContext,
867-
],
868-
I,
869-
],
870-
Awaitable[temporalio.nexus.WorkflowHandle[O]],
871-
],
872-
str,
873-
],
857+
operation: Union[nexusrpc.Operation[I, O], str, Callable[..., Any]],
874858
input: Any,
875859
output_type: Optional[Type[O]] = None,
876860
schedule_to_close_timeout: Optional[timedelta] = None,
@@ -4432,21 +4416,7 @@ def operation_token(self) -> Optional[str]:
44324416
async def start_nexus_operation(
44334417
endpoint: str,
44344418
service: str,
4435-
operation: Union[
4436-
nexusrpc.Operation[I, O],
4437-
Callable[[Any], nexusrpc.handler.OperationHandler[I, O]],
4438-
Callable[
4439-
[
4440-
S,
4441-
Union[
4442-
nexusrpc.handler.StartOperationContext, WorkflowRunOperationContext
4443-
],
4444-
I,
4445-
],
4446-
Awaitable[temporalio.nexus.WorkflowHandle[O]],
4447-
],
4448-
str,
4449-
],
4419+
operation: Union[nexusrpc.Operation[I, O], str, Callable[..., Any]],
44504420
input: Any,
44514421
*,
44524422
output_type: Optional[Type[O]] = None,
@@ -5224,22 +5194,7 @@ def __init__(
52245194
# TODO(nexus-prerelease): should it be an error to use a reference to a method on a class other than that supplied?
52255195
async def start_operation(
52265196
self,
5227-
operation: Union[
5228-
nexusrpc.Operation[I, O],
5229-
Callable[[S], nexusrpc.handler.OperationHandler[I, O]],
5230-
Callable[
5231-
[
5232-
S,
5233-
Union[
5234-
nexusrpc.handler.StartOperationContext,
5235-
WorkflowRunOperationContext,
5236-
],
5237-
I,
5238-
],
5239-
Awaitable[temporalio.nexus.WorkflowHandle[O]],
5240-
],
5241-
str,
5242-
],
5197+
operation: Union[nexusrpc.Operation[I, O], str, Callable[..., Any]],
52435198
input: I,
52445199
*,
52455200
output_type: Optional[Type[O]] = None,
@@ -5259,22 +5214,7 @@ async def start_operation(
52595214
# TODO(nexus-prerelease): overloads: no-input, ret type
52605215
async def execute_operation(
52615216
self,
5262-
operation: Union[
5263-
nexusrpc.Operation[I, O],
5264-
Callable[[S], nexusrpc.handler.OperationHandler[I, O]],
5265-
Callable[
5266-
[
5267-
S,
5268-
Union[
5269-
nexusrpc.handler.StartOperationContext,
5270-
WorkflowRunOperationContext,
5271-
],
5272-
I,
5273-
],
5274-
Awaitable[temporalio.nexus.WorkflowHandle[O]],
5275-
],
5276-
str,
5277-
],
5217+
operation: Union[nexusrpc.Operation[I, O], str, Callable[..., Any]],
52785218
input: I,
52795219
*,
52805220
output_type: Optional[Type[O]] = None,

0 commit comments

Comments
 (0)