Coverage for polar/worker/_encoder.py: 85%
11 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 17:15 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 17:15 +0000
1import json 1ab
2import uuid 1ab
3from typing import Any 1ab
5import dramatiq 1ab
8def _json_obj_serializer(obj: Any) -> Any: 1ab
9 if isinstance(obj, uuid.UUID): 9 ↛ 11line 9 didn't jump to line 11 because the condition on line 9 was always true1c
10 return str(obj) 1c
11 raise TypeError(f"Object of type {type(obj)} is not JSON serializable")
14class JSONEncoder(dramatiq.JSONEncoder): 1ab
15 def encode(self, data: dict[str, Any]) -> bytes: 1ab
16 return json.dumps( 1c
17 data, separators=(",", ":"), default=_json_obj_serializer
18 ).encode("utf-8")