Skip to content

Commit 6caa75b

Browse files
JRRudy1davidhewitt
authored andcommitted
Fixed example crate attempting to clone a PyObject.
1 parent 234227a commit 6caa75b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

examples/simple/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ use pyo3::{
1616
#[pymodule]
1717
fn rust_ext<'py>(m: &Bound<'py, PyModule>) -> PyResult<()> {
1818
// example using generic PyObject
19-
fn head(x: ArrayViewD<'_, PyObject>) -> PyResult<PyObject> {
19+
fn head(py: Python<'_>, x: ArrayViewD<'_, PyObject>) -> PyResult<PyObject> {
2020
x.get(0)
21-
.cloned()
21+
.map(|obj| obj.clone_ref(py))
2222
.ok_or_else(|| PyIndexError::new_err("array index out of range"))
2323
}
2424

@@ -49,7 +49,7 @@ fn rust_ext<'py>(m: &Bound<'py, PyModule>) -> PyResult<()> {
4949
#[pyfn(m)]
5050
#[pyo3(name = "head")]
5151
fn head_py<'py>(x: PyReadonlyArrayDyn<'py, PyObject>) -> PyResult<PyObject> {
52-
head(x.as_array())
52+
head(x.py(), x.as_array())
5353
}
5454

5555
// wrapper of `axpy`

0 commit comments

Comments
 (0)