Skip to content

Commit

Permalink
Merge pull request #3391 from alex/drop-trait
Browse files Browse the repository at this point in the history
Remove usage of `AsPyPointer` in traits for convergint to PyObject
  • Loading branch information
davidhewitt committed Aug 16, 2023
2 parents 75da891 + c259e77 commit 0375d57
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 0375d57

Please sign in to comment.