Skip to content

Commit

Permalink
Fixed example crate attempting to clone a PyObject.
Browse files Browse the repository at this point in the history
  • Loading branch information
JRRudy1 authored and davidhewitt committed Oct 6, 2024
1 parent 234227a commit 6caa75b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions examples/simple/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use pyo3::{
#[pymodule]
fn rust_ext<'py>(m: &Bound<'py, PyModule>) -> PyResult<()> {
// example using generic PyObject
fn head(x: ArrayViewD<'_, PyObject>) -> PyResult<PyObject> {
fn head(py: Python<'_>, x: ArrayViewD<'_, PyObject>) -> PyResult<PyObject> {
x.get(0)
.cloned()
.map(|obj| obj.clone_ref(py))
.ok_or_else(|| PyIndexError::new_err("array index out of range"))
}

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

// wrapper of `axpy`
Expand Down

0 comments on commit 6caa75b

Please sign in to comment.