Skip to content

Commit 308ca5b

Browse files
committed
Cleanup
1 parent 7a03e39 commit 308ca5b

File tree

3 files changed

+8
-52
lines changed

3 files changed

+8
-52
lines changed

temporalio/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6511,9 +6511,9 @@ async def fail_async_activity(self, input: FailAsyncActivityInput) -> None:
65116511
failure = temporalio.api.failure.v1.Failure()
65126512
await data_converter.encode_failure(input.error, failure)
65136513
last_heartbeat_details = (
6514-
None
6515-
if not input.last_heartbeat_details
6516-
else await data_converter.encode_wrapper(input.last_heartbeat_details)
6514+
await data_converter.encode_wrapper(input.last_heartbeat_details)
6515+
if input.last_heartbeat_details
6516+
else None
65176517
)
65186518
if isinstance(input.id_or_token, AsyncActivityIDReference):
65196519
await self._client.workflow_service.respond_activity_task_failed_by_id(

temporalio/converter.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,17 @@ class SerializationContext(ABC):
7272
Provides contextual information during serialization and deserialization operations.
7373
7474
Examples:
75-
7675
- In client code, when starting a workflow, or sending a signal/update/query to a workflow, or
7776
receiving the result of an update/query, or handling an exception from a workflow, the context
7877
type is :py:class:`WorkflowSerializationContext` and the workflow ID set of the target
7978
workflow will be set in the context.
80-
8179
- In workflow code, when operating on a payload being sent/received to/from a child workflow, or
8280
handling an exception from a child workflow, the context type is
8381
:py:class:`WorkflowSerializationContext` and the workflow ID is that of the child workflow,
8482
not of the currently executing (i.e. parent) workflow.
85-
8683
- In workflow code, when operating on a payload to be sent/received to/from an activity, the
8784
context type is :py:class:`ActivitySerializationContext` and the workflow ID is that of the
8885
currently-executing workflow. ActivitySerializationContext is also set on operations
89-
9086
"""
9187

9288
pass

tests/test_serialization_context.py

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
import asyncio
44
import dataclasses
5-
import inspect
65
import uuid
76
from collections import defaultdict
87
from dataclasses import dataclass, field
98
from datetime import timedelta
109
from itertools import zip_longest
1110
from pprint import pformat
12-
from typing import Any, List, Literal, Never, Optional, Sequence, Type, cast
11+
from typing import Any, List, Literal, Optional, Sequence, Type, cast
1312
from warnings import warn
1413

1514
import pytest
1615
from pydantic import BaseModel
16+
from typing_extensions import Never
1717

1818
from temporalio import activity, workflow
1919
from temporalio.api.common.v1 import Payload
@@ -53,7 +53,6 @@ class TraceItem:
5353
]
5454
context: dict[str, Any]
5555
in_workflow: bool
56-
caller_location: list[str] = field(default_factory=list)
5756

5857
def __eq__(self, other: object) -> bool:
5958
if not isinstance(other, TraceItem):
@@ -131,7 +130,6 @@ def to_payload(self, value: Any) -> Optional[Payload]:
131130
in_workflow=workflow.in_workflow(),
132131
method="to_payload",
133132
context=dataclasses.asdict(self.context),
134-
caller_location=get_caller_location(),
135133
)
136134
)
137135
elif isinstance(self.context, ActivitySerializationContext):
@@ -141,7 +139,6 @@ def to_payload(self, value: Any) -> Optional[Payload]:
141139
in_workflow=workflow.in_workflow(),
142140
method="to_payload",
143141
context=dataclasses.asdict(self.context),
144-
caller_location=get_caller_location(),
145142
)
146143
)
147144
else:
@@ -164,7 +161,6 @@ def from_payload(self, payload: Payload, type_hint: Optional[Type] = None) -> An
164161
in_workflow=workflow.in_workflow(),
165162
method="from_payload",
166163
context=dataclasses.asdict(self.context),
167-
caller_location=get_caller_location(),
168164
)
169165
)
170166
elif isinstance(self.context, ActivitySerializationContext):
@@ -174,7 +170,6 @@ def from_payload(self, payload: Payload, type_hint: Optional[Type] = None) -> An
174170
in_workflow=workflow.in_workflow(),
175171
method="from_payload",
176172
context=dataclasses.asdict(self.context),
177-
caller_location=get_caller_location(),
178173
)
179174
)
180175
else:
@@ -1302,46 +1297,11 @@ def assert_trace(trace: list[TraceItem], expected: list[TraceItem]):
13021297
history: list[str] = []
13031298
for item, expected_item in zip_longest(trace, expected):
13041299
if item is None:
1305-
raise AssertionError(
1306-
f"Fewer items in trace than expected.\n\n History:\n{'\n'.join(history)}"
1307-
)
1300+
raise AssertionError("Fewer items in trace than expected.")
13081301
if expected_item is None:
1309-
raise AssertionError(
1310-
f"More items in trace than expected.\n\n History:\n{'\n'.join(history)}"
1311-
)
1302+
raise AssertionError("More items in trace than expected.")
13121303
if item != expected_item:
13131304
raise AssertionError(
1314-
f"Item:\n{pformat(item)}\n\ndoes not match expected:\n\n {pformat(expected_item)}.\n\n History:\n{'\n'.join(history)}"
1305+
f"Item:\n{pformat(item)}\n\ndoes not match expected:\n\n {pformat(expected_item)}."
13151306
)
13161307
history.append(f"{item.context_type} {item.method}")
1317-
1318-
1319-
def get_caller_location() -> list[str]:
1320-
"""Get 3 stack frames starting from the first that's not in test_serialization_context.py or temporalio/converter.py."""
1321-
frame = inspect.currentframe()
1322-
result: list[str] = []
1323-
found_first = False
1324-
1325-
# Walk up the stack
1326-
while frame and len(result) < 3:
1327-
frame = frame.f_back
1328-
if not frame:
1329-
break
1330-
1331-
file_path = frame.f_code.co_filename
1332-
1333-
# Skip frames from test file and converter.py until we find the first one
1334-
if not found_first:
1335-
if "test_serialization_context.py" in file_path:
1336-
continue
1337-
if file_path.endswith("temporalio/converter.py"):
1338-
continue
1339-
found_first = True
1340-
1341-
result.append(f"{file_path}:{frame.f_lineno}")
1342-
1343-
# Pad with "unknown:0" if we didn't get 3 frames
1344-
while len(result) < 3:
1345-
result.append("unknown:0")
1346-
1347-
return result

0 commit comments

Comments
 (0)