MCPcopy Create free account
hub / github.com/catboost/catboost / serialize

Function serialize

library/python/testing/yatest_lib/external.py:61–83  ·  view source on GitHub ↗

Serialize value to json-convertible object Ensures that all components of value can be serialized to json :param value: object to be serialized

(value)

Source from the content-addressed store, hash-verified

59
60
61def serialize(value):
62 """
63 Serialize value to json-convertible object
64 Ensures that all components of value can be serialized to json
65 :param value: object to be serialized
66 """
67 def _serialize(val, _):
68 if val is None:
69 return val
70 if isinstance(val, six.string_types) or isinstance(val, bytes):
71 return tools.to_utf8(val)
72 if isinstance(val, enum.Enum):
73 return str(val)
74 if isinstance(val, six.integer_types) or type(val) in [float, bool]:
75 return val
76 if is_external(val):
77 return dict(val)
78 if isinstance(val, (date, datetime)):
79 return repr(val)
80 if is_coroutine(val):
81 return None
82 raise ValueError("Cannot serialize value '{}' of type {}".format(val, type(val)))
83 return apply(_serialize, value, apply_to_keys=True)
84
85
86def is_external(value):

Callers

nothing calls this directly

Calls 1

applyFunction · 0.70

Tested by

no test coverage detected