22
33import asyncio
44import dataclasses
5- import inspect
65import uuid
76from collections import defaultdict
87from dataclasses import dataclass , field
98from datetime import timedelta
109from itertools import zip_longest
1110from 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
1312from warnings import warn
1413
1514import pytest
1615from pydantic import BaseModel
16+ from typing_extensions import Never
1717
1818from temporalio import activity , workflow
1919from 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 \n does not match expected:\n \n { pformat (expected_item )} .\n \n History: \n { ' \n ' . join ( history ) } "
1305+ f"Item:\n { pformat (item )} \n \n does 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