Remove usage of `AsPyPointer` in traits for convergint to PyObject

Refs #3358
This commit is contained in:
Alex Gaynor 2023-08-15 21:31:25 -04:00
parent 82b1e55e2b
commit c259e77ca2
Failed to extract signature
2 changed files with 9 additions and 2 deletions

View File

@ -0,0 +1 @@
Replace `AsPyPointer` with `AsRef<PyAny>` as a bound in the blanket implementation of `From<&T> for PyObject`

View File

@ -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 impl<T> std::convert::From<&'_ T> for PyObject
where where
T: AsPyPointer + PyNativeType, T: PyNativeType + AsRef<PyAny>,
{ {
fn from(obj: &T) -> Self { 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()) }
} }
} }