From c259e77ca26509fab486d6ec9b27d4a2439b5408 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Tue, 15 Aug 2023 21:31:25 -0400 Subject: [PATCH] Remove usage of `AsPyPointer` in traits for convergint to PyObject Refs #3358 --- newsfragments/3391.changed.md | 1 + src/instance.rs | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 newsfragments/3391.changed.md 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()) } } }