Skip to content

Commit 3c37838

Browse files
committed
Cleanup
1 parent b826097 commit 3c37838

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

temporalio/worker/_command_aware_visitor.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
import contextvars
44
from contextlib import contextmanager
55
from dataclasses import dataclass
6-
from typing import Any, Iterator, Optional, Type
6+
from typing import Iterator, Optional
77

88
from temporalio.api.enums.v1.command_type_pb2 import CommandType
99
from temporalio.bridge._visitor import PayloadVisitor, VisitorFunctions
10-
from temporalio.bridge.proto.workflow_activation import workflow_activation_pb2
1110
from temporalio.bridge.proto.workflow_activation.workflow_activation_pb2 import (
1211
ResolveActivity,
1312
ResolveChildWorkflowExecution,
@@ -17,7 +16,6 @@
1716
ResolveRequestCancelExternalWorkflow,
1817
ResolveSignalExternalWorkflow,
1918
)
20-
from temporalio.bridge.proto.workflow_commands import workflow_commands_pb2
2119
from temporalio.bridge.proto.workflow_commands.workflow_commands_pb2 import (
2220
ScheduleActivity,
2321
ScheduleLocalActivity,
@@ -150,27 +148,13 @@ async def _visit_coresdk_workflow_activation_ResolveNexusOperation(
150148
)
151149

152150

153-
def _get_workflow_command_protos_with_seq() -> Iterator[Type[Any]]:
154-
"""Get concrete classes of all workflow command protos with a seq field."""
155-
for descriptor in workflow_commands_pb2.DESCRIPTOR.message_types_by_name.values():
156-
if "seq" in descriptor.fields_by_name:
157-
yield descriptor._concrete_class
158-
159-
160-
def _get_workflow_activation_job_protos_with_seq() -> Iterator[Type[Any]]:
161-
"""Get concrete classes of all workflow activation job protos with a seq field."""
162-
for descriptor in workflow_activation_pb2.DESCRIPTOR.message_types_by_name.values():
163-
if "seq" in descriptor.fields_by_name:
164-
yield descriptor._concrete_class
165-
166-
167151
@contextmanager
168152
def current_command(
169-
command_type: Optional[CommandType.ValueType], command_seq: int
153+
command_type: CommandType.ValueType, command_seq: int
170154
) -> Iterator[None]:
171155
"""Context manager for setting command info."""
172156
token = current_command_info.set(
173-
CommandInfo(command_type=command_type, command_seq=command_seq) # type: ignore
157+
CommandInfo(command_type=command_type, command_seq=command_seq)
174158
)
175159
try:
176160
yield

tests/worker/test_command_aware_visitor.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""Test that CommandAwarePayloadVisitor handles all commands with seq fields that have payloads."""
22

3+
from typing import Any, Iterator, Type
4+
35
from temporalio.bridge._visitor import PayloadVisitor
4-
from temporalio.worker._command_aware_visitor import (
5-
CommandAwarePayloadVisitor,
6-
_get_workflow_activation_job_protos_with_seq,
7-
_get_workflow_command_protos_with_seq,
8-
)
6+
from temporalio.bridge.proto.workflow_activation import workflow_activation_pb2
7+
from temporalio.bridge.proto.workflow_commands import workflow_commands_pb2
8+
from temporalio.worker._command_aware_visitor import CommandAwarePayloadVisitor
99

1010

1111
def test_command_aware_visitor_has_methods_for_all_seq_protos_with_payloads():
@@ -73,3 +73,17 @@ def test_command_aware_visitor_has_methods_for_all_seq_protos_with_payloads():
7373
assert (
7474
len(jobs_with_payloads) == len(job_protos) - 1
7575
), "Should have exactly one activation job without payloads (FireTimer)"
76+
77+
78+
def _get_workflow_command_protos_with_seq() -> Iterator[Type[Any]]:
79+
"""Get concrete classes of all workflow command protos with a seq field."""
80+
for descriptor in workflow_commands_pb2.DESCRIPTOR.message_types_by_name.values():
81+
if "seq" in descriptor.fields_by_name:
82+
yield descriptor._concrete_class
83+
84+
85+
def _get_workflow_activation_job_protos_with_seq() -> Iterator[Type[Any]]:
86+
"""Get concrete classes of all workflow activation job protos with a seq field."""
87+
for descriptor in workflow_activation_pb2.DESCRIPTOR.message_types_by_name.values():
88+
if "seq" in descriptor.fields_by_name:
89+
yield descriptor._concrete_class

0 commit comments

Comments
 (0)