diff --git a/cozo-lib-python/src/lib.rs b/cozo-lib-python/src/lib.rs index 11bbe8d7..bd0381e6 100644 --- a/cozo-lib-python/src/lib.rs +++ b/cozo-lib-python/src/lib.rs @@ -12,7 +12,7 @@ use std::thread; use miette::{IntoDiagnostic, Report, Result}; use pyo3::exceptions::PyException; use pyo3::prelude::*; -use pyo3::types::{PyBytes, PyDict, PyList, PyString, PyTuple}; +use pyo3::types::{PyBool, PyByteArray, PyBytes, PyDict, PyList, PyString, PyTuple}; use serde_json::json; use cozo::*; @@ -46,14 +46,18 @@ fn py_to_named_rows(ob: &PyAny) -> PyResult { fn py_to_value(ob: &PyAny) -> PyResult { Ok(if ob.is_none() { DataValue::Null + } else if let Ok(b) = ob.downcast::() { + DataValue::from(b.is_true()) } else if let Ok(i) = ob.extract::() { DataValue::from(i) } else if let Ok(f) = ob.extract::() { DataValue::from(f) } else if let Ok(s) = ob.extract::() { DataValue::from(s) - } else if let Ok(b) = ob.extract::>() { - DataValue::Bytes(b) + } else if let Ok(b) = ob.downcast::() { + DataValue::Bytes(b.as_bytes().to_vec()) + } else if let Ok(b) = ob.downcast::() { + DataValue::Bytes(unsafe { b.as_bytes() }.to_vec()) } else if let Ok(l) = ob.downcast::() { let mut coll = Vec::with_capacity(l.len()); for el in l {