Skip to content

Commit

Permalink
Fixed IntoPy<PyObject> for PyBackedBytes impl to create bytes for…
Browse files Browse the repository at this point in the history
… both storage types as intended. Updated test to properly catch the error.
  • Loading branch information
JRRudy1 committed May 31, 2024
1 parent 69977ff commit 43fb3f7
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/pybacked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,7 @@ impl IntoPy<Py<PyAny>> for PyBackedBytes {
fn into_py(self, py: Python<'_>) -> Py<PyAny> {
match self.storage {
PyBackedBytesStorage::Python(bytes) => bytes.into_any(),
PyBackedBytesStorage::Rust(bytes) => {
PyByteArray::new_bound(py, &bytes).into_any().unbind()
}
PyBackedBytesStorage::Rust(bytes) => PyBytes::new_bound(py, &bytes).into_any().unbind(),
}
}
}
Expand Down Expand Up @@ -412,9 +410,9 @@ mod test {
let to_object = rust_backed_bytes.to_object(py).into_bound(py);
assert!(&to_object.is_exact_instance_of::<PyBytes>());
assert_eq!(&to_object.extract::<PyBackedBytes>().unwrap(), b"abcde");
let into_py = rust_backed_bytes.into_py(py);
assert!(&to_object.is_exact_instance_of::<PyBytes>());
assert_eq!(&into_py.extract::<PyBackedBytes>(py).unwrap(), b"abcde");
let into_py = rust_backed_bytes.into_py(py).into_bound(py);
assert!(&into_py.is_exact_instance_of::<PyBytes>());
assert_eq!(&into_py.extract::<PyBackedBytes>().unwrap(), b"abcde");
});
}

Expand Down

0 comments on commit 43fb3f7

Please sign in to comment.