@@ -247,22 +247,34 @@ def event(value: str, payload: Union[str, int, float] = "") -> None:
247247 """
248248 context = _current_build_context .value
249249 if context is None :
250- raise InvalidArgument ("Cannot make record events outside of a test" )
250+ raise InvalidArgument ("Cannot record events outside of a test" )
251251
252- payload = _event_to_string (payload , (str , int , float ))
253- context .data .events [_event_to_string (value )] = payload
252+ avoid_realization = context .data .provider .avoid_realization
253+ payload = _event_to_string (
254+ payload , allowed_types = (str , int , float ), avoid_realization = avoid_realization
255+ )
256+ value = _event_to_string (value , avoid_realization = avoid_realization )
257+ context .data .events [value ] = payload
254258
255259
256260_events_to_strings : WeakKeyDictionary = WeakKeyDictionary ()
257261
258262
259- def _event_to_string (event , allowed_types = str ):
263+ def _event_to_string (event , * , allowed_types = str , avoid_realization ):
260264 if isinstance (event , allowed_types ):
261265 return event
266+
267+ # _events_to_strings is a cache which persists across iterations, causing
268+ # problems for symbolic backends. see
269+ # https://github.com/pschanely/hypothesis-crosshair/issues/41
270+ if avoid_realization :
271+ return str (event )
272+
262273 try :
263274 return _events_to_strings [event ]
264275 except (KeyError , TypeError ):
265276 pass
277+
266278 result = str (event )
267279 try :
268280 _events_to_strings [event ] = result
0 commit comments