Skip to content

Commit

Permalink
Upgrade pyo3 to 0.23
Browse files Browse the repository at this point in the history
  • Loading branch information
414owen authored and torymur committed Feb 10, 2025
1 parent 2dfb1dd commit 33d6deb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ rust-version = "1.71.1"
[dependencies]
once_cell = "1.20"
thiserror = "2.0"
pyo3 = { version = "0.22.0", features = ["extension-module"], optional = true }
pyo3 = { version = "0.23", features = ["extension-module"], optional = true }
regex = "1.10.6"
serde-pyobject = { version = "0.4.0", optional = true }
serde-pyobject = { version = "0.5.0", optional = true }
serde_json = { version = "1.0", features = ["preserve_order"] }
serde = {version = "1.0", features = ["derive"]}
bincode = "2.0.0-rc.3"
Expand Down
16 changes: 7 additions & 9 deletions src/python_bindings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,12 @@ impl PyGuide {

fn __reduce__(&self) -> PyResult<(PyObject, (Vec<u8>,))> {
Python::with_gil(|py| {
let cls =
PyModule::import_bound(py, "outlines_core.outlines_core_rs")?.getattr("Guide")?;
let cls = PyModule::import(py, "outlines_core.outlines_core_rs")?.getattr("Guide")?;
let binary_data: Vec<u8> =
bincode::encode_to_vec(self, config::standard()).map_err(|e| {
PyErr::new::<PyValueError, _>(format!("Serialization of Guide failed: {}", e))
})?;
Ok((cls.getattr("from_binary")?.to_object(py), (binary_data,)))
Ok((cls.getattr("from_binary")?.unbind(), (binary_data,)))
})
}

Expand Down Expand Up @@ -167,13 +166,12 @@ impl PyIndex {

fn __reduce__(&self) -> PyResult<(PyObject, (Vec<u8>,))> {
Python::with_gil(|py| {
let cls =
PyModule::import_bound(py, "outlines_core.outlines_core_rs")?.getattr("Index")?;
let cls = PyModule::import(py, "outlines_core.outlines_core_rs")?.getattr("Index")?;
let binary_data: Vec<u8> = bincode::encode_to_vec(&self.0, config::standard())
.map_err(|e| {
PyErr::new::<PyValueError, _>(format!("Serialization of Index failed: {}", e))
})?;
Ok((cls.getattr("from_binary")?.to_object(py), (binary_data,)))
Ok((cls.getattr("from_binary")?.unbind(), (binary_data,)))
})
}

Expand Down Expand Up @@ -300,16 +298,16 @@ impl PyVocabulary {

fn __reduce__(&self) -> PyResult<(PyObject, (Vec<u8>,))> {
Python::with_gil(|py| {
let cls = PyModule::import_bound(py, "outlines_core.outlines_core_rs")?
.getattr("Vocabulary")?;
let cls =
PyModule::import(py, "outlines_core.outlines_core_rs")?.getattr("Vocabulary")?;
let binary_data: Vec<u8> =
bincode::encode_to_vec(self, config::standard()).map_err(|e| {
PyErr::new::<PyValueError, _>(format!(
"Serialization of Vocabulary failed: {}",
e
))
})?;
Ok((cls.getattr("from_binary")?.to_object(py), (binary_data,)))
Ok((cls.getattr("from_binary")?.unbind(), (binary_data,)))
})
}

Expand Down

0 comments on commit 33d6deb

Please sign in to comment.