Skip to content

Commit

Permalink
Remove usage of AsPyPointer in IntoPy<PyObject> trait implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
alex committed Aug 16, 2023
1 parent 82b1e55 commit d509b9c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions newsfragments/3393.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replace blanket `impl IntoPy<PyObject> for &T where T: AsPyPointer` with implementations of `impl IntoPy<PyObject>` for `&PyAny`, `&T where T: AsRef<PyAny>`, and `&Py<T>`.
11 changes: 9 additions & 2 deletions src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,20 @@ impl IntoPy<PyObject> for () {
}
}

impl IntoPy<PyObject> for &'_ PyAny {
#[inline]
fn into_py(self, py: Python<'_>) -> PyObject {
unsafe { PyObject::from_borrowed_ptr(py, self.as_ptr()) }
}
}

impl<T> IntoPy<PyObject> for &'_ T
where
T: AsPyPointer,
T: AsRef<PyAny>,
{
#[inline]
fn into_py(self, py: Python<'_>) -> PyObject {
unsafe { PyObject::from_borrowed_ptr(py, self.as_ptr()) }
unsafe { PyObject::from_borrowed_ptr(py, self.as_ref().as_ptr()) }
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,13 @@ impl<T> IntoPy<PyObject> for Py<T> {
}
}

impl<T> IntoPy<PyObject> for &'_ Py<T> {
#[inline]
fn into_py(self, py: Python<'_>) -> PyObject {
unsafe { PyObject::from_borrowed_ptr(py, self.as_ptr()) }
}
}

impl<T> crate::AsPyPointer for Py<T> {
/// Gets the underlying FFI pointer, returns a borrowed pointer.
#[inline]
Expand Down

0 comments on commit d509b9c

Please sign in to comment.