Skip to content

Commit 82d4ff1

Browse files
committed
fix: avoid IntoPy in Python bindings
1 parent bb67b65 commit 82d4ff1

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

python/src/lib.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use std::sync::Arc;
33
use chrono::{SecondsFormat, Utc};
44
use pyo3::exceptions::PyRuntimeError;
55
use pyo3::prelude::*;
6-
use pyo3::IntoPy;
76
use pyo3::types::{PyBytes, PyDict, PyType};
7+
use pyo3::IntoPyObject;
88
use tokio::runtime::Runtime;
99

1010
use lance_context::serde::CONTENT_TYPE_TEXT;
@@ -69,9 +69,7 @@ impl Context {
6969
let (content_type, text_payload, binary_payload, inner_content) =
7070
match content.extract::<&[u8]>() {
7171
Ok(bytes) => (
72-
data_type
73-
.unwrap_or(DEFAULT_BINARY_CONTENT_TYPE)
74-
.to_string(),
72+
data_type.unwrap_or(DEFAULT_BINARY_CONTENT_TYPE).to_string(),
7573
None,
7674
Some(bytes.to_vec()),
7775
BINARY_PLACEHOLDER.to_string(),
@@ -147,7 +145,11 @@ impl Context {
147145
}
148146

149147
fn new_run_id() -> String {
150-
format!("run-{}-{}", Utc::now().timestamp_micros(), std::process::id())
148+
format!(
149+
"run-{}-{}",
150+
Utc::now().timestamp_micros(),
151+
std::process::id()
152+
)
151153
}
152154

153155
fn search_hit_to_py(py: Python<'_>, hit: SearchResult) -> PyResult<PyObject> {
@@ -180,9 +182,9 @@ fn search_hit_to_py(py: Python<'_>, hit: SearchResult) -> PyResult<PyObject> {
180182
state_dict.set_item("active_plan_id", metadata.active_plan_id)?;
181183
state_dict.set_item("tokens_used", metadata.tokens_used)?;
182184
state_dict.set_item("custom", metadata.custom)?;
183-
state_dict.into_py(py)
185+
state_dict.into_pyobject(py)?.unbind().into()
184186
}
185-
None => py.None().into_py(py),
187+
None => py.None().into_pyobject(py)?.unbind().into(),
186188
};
187189
dict.set_item("state_metadata", state_obj)?;
188190
dict.set_item("content_type", content_type)?;
@@ -193,7 +195,7 @@ fn search_hit_to_py(py: Python<'_>, hit: SearchResult) -> PyResult<PyObject> {
193195
}
194196
dict.set_item("embedding", embedding)?;
195197
dict.set_item("distance", distance)?;
196-
Ok(dict.into_py(py))
198+
Ok(dict.into_pyobject(py)?.unbind().into())
197199
}
198200

199201
fn to_py_err<E: std::fmt::Display>(err: E) -> PyErr {

0 commit comments

Comments
 (0)