Skip to content

Commit

Permalink
Remove usage of AsPyPointer in traits for convergint to PyObject
Browse files Browse the repository at this point in the history
Refs #3358
  • Loading branch information
alex committed Aug 16, 2023
1 parent 82b1e55 commit c259e77
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions newsfragments/3391.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replace `AsPyPointer` with `AsRef<PyAny>` as a bound in the blanket implementation of `From<&T> for PyObject`
10 changes: 8 additions & 2 deletions src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,12 +933,18 @@ impl<T> crate::AsPyPointer for Py<T> {
}
}

impl std::convert::From<&'_ PyAny> for PyObject {
fn from(obj: &PyAny) -> Self {
unsafe { Py::from_borrowed_ptr(obj.py(), obj.as_ptr()) }
}
}

impl<T> std::convert::From<&'_ T> for PyObject
where
T: AsPyPointer + PyNativeType,
T: PyNativeType + AsRef<PyAny>,
{
fn from(obj: &T) -> Self {
unsafe { Py::from_borrowed_ptr(obj.py(), obj.as_ptr()) }
unsafe { Py::from_borrowed_ptr(obj.py(), obj.as_ref().as_ptr()) }
}
}

Expand Down

0 comments on commit c259e77

Please sign in to comment.