diff --git a/newsfragments/3391.changed.md b/newsfragments/3391.changed.md new file mode 100644 index 00000000000..fd04faaba0c --- /dev/null +++ b/newsfragments/3391.changed.md @@ -0,0 +1 @@ +Replace `AsPyPointer` with `AsRef` as a bound in the blanket implementation of `From<&T> for PyObject` diff --git a/src/instance.rs b/src/instance.rs index b363c0a0342..a80ab7d7745 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -933,12 +933,18 @@ impl crate::AsPyPointer for Py { } } +impl std::convert::From<&'_ PyAny> for PyObject { + fn from(obj: &PyAny) -> Self { + unsafe { Py::from_borrowed_ptr(obj.py(), obj.as_ptr()) } + } +} + impl std::convert::From<&'_ T> for PyObject where - T: AsPyPointer + PyNativeType, + T: PyNativeType + AsRef, { 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()) } } }