Coverage for polar/worker/_encoder.py: 85%

11 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-07 12:42 +0000

1import json 

2import uuid 

3from typing import Any 

4 

5import dramatiq 

6 

7 

8def _json_obj_serializer(obj: Any) -> Any: 

9 if isinstance(obj, uuid.UUID): 9 ↛ 11line 9 didn't jump to line 11 because the condition on line 9 was always true

10 return str(obj) 

11 raise TypeError(f"Object of type {type(obj)} is not JSON serializable") 

12 

13 

14class JSONEncoder(dramatiq.JSONEncoder): 

15 def encode(self, data: dict[str, Any]) -> bytes: 

16 return json.dumps( 

17 data, separators=(",", ":"), default=_json_obj_serializer 

18 ).encode("utf-8")