in src/serialize/per_type/dict.rs [421:459]
fn pyobject_to_string(
key: *mut pyo3_ffi::PyObject,
opts: crate::opt::Opt,
) -> Result<CompactString, SerializeError> {
match pyobject_to_obtype(key, opts) {
ObType::None => Ok(CompactString::const_new("null")),
ObType::Bool => {
if unsafe { key == TRUE } {
Ok(CompactString::const_new("true"))
} else {
Ok(CompactString::const_new("false"))
}
}
ObType::Int => non_str_int(key),
ObType::Float => non_str_float(key),
ObType::Datetime => non_str_datetime(key, opts),
ObType::Date => non_str_date(key),
ObType::Time => non_str_time(key, opts),
ObType::Uuid => non_str_uuid(key),
ObType::Enum => {
let value = ffi!(PyObject_GetAttr(key, VALUE_STR));
debug_assert!(ffi!(Py_REFCNT(value)) >= 2);
let ret = Self::pyobject_to_string(value, opts);
ffi!(Py_DECREF(value));
ret
}
ObType::Str => non_str_str(key),
ObType::StrSubclass => non_str_str_subclass(key),
ObType::Tuple
| ObType::NumpyScalar
| ObType::NumpyArray
| ObType::Dict
| ObType::List
| ObType::Dataclass
| ObType::Fragment
| ObType::PyTorchTensor
| ObType::Unknown => Err(SerializeError::DictKeyInvalidType),
}
}