mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-25 04:20:02 +00:00
24 lines
616 B
Python
24 lines
616 B
Python
import typing as t
|
|
|
|
import griffe
|
|
from _griffe.encoders import _json_encoder_map
|
|
|
|
|
|
class CustomEncoder(griffe.JSONEncoder):
|
|
def default(self, obj: t.Any) -> t.Any:
|
|
"""Return a serializable representation of the given object.
|
|
|
|
Parameters:
|
|
obj: The object to serialize.
|
|
|
|
Returns:
|
|
A serializable representation.
|
|
"""
|
|
|
|
try:
|
|
if isinstance(obj, griffe.Expr):
|
|
return str(obj)
|
|
return obj.as_dict(full=self.full)
|
|
except AttributeError:
|
|
return _json_encoder_map.get(type(obj), super().default)(obj)
|