Coverage for /Users/eugene/Development/robotnikmq/robotnikmq/utils.py: 100%

1 from json import JSONEncoder, dumps

2 from pathlib import Path

3 from typing import Any

4

5 from typeguard import typechecked

6

7

8 class MyEncoder(JSONEncoder): # pragma: no cover # not directly used in code

9 @typechecked

10 def default(self, obj: Any) -> Any: # pylint: disable=W0221

11 if isinstance(obj, Path):

12 return str(obj)

13 return JSONEncoder.default(self, obj)

14

15

16@typechecked

17 def to_json(obj: Any) -> Any:

18 return dumps(obj, cls=MyEncoder)