Skip to content

Commit

Permalink
Revert "refactor: add FromRef trait to cast from &T to either `&T…
Browse files Browse the repository at this point in the history
…` or `Py<T>`"

This reverts commit 974161a.
  • Loading branch information
wyfo committed Nov 20, 2023
1 parent 974161a commit 9a82505
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 28 deletions.
10 changes: 4 additions & 6 deletions pyo3-macros-backend/src/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,14 @@ impl FnType {
}
FnType::FnClass | FnType::FnNewClass => {
quote! {
_pyo3::impl_::extract_argument::FromRef::from_ref(
_pyo3::types::PyType::from_type_ptr(py, _slf as *mut _pyo3::ffi::PyTypeObject)
),
#[allow(clippy::useless_conversion)]
::std::convert::Into::into(_pyo3::types::PyType::from_type_ptr(py, _slf as *mut _pyo3::ffi::PyTypeObject)),
}
}
FnType::FnModule => {
quote! {
_pyo3::impl_::extract_argument::FromRef::from_ref(
py.from_borrowed_ptr::<_pyo3::types::PyModule>(_slf)
),
#[allow(clippy::useless_conversion)]
::std::convert::Into::into(py.from_borrowed_ptr::<_pyo3::types::PyModule>(_slf)),
}
}
}
Expand Down
23 changes: 1 addition & 22 deletions src/impl_/extract_argument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ use crate::{
ffi,
pyclass::boolean_struct::False,
types::{PyDict, PyString, PyTuple},
FromPyObject, IntoPy, Py, PyAny, PyClass, PyErr, PyRef, PyRefMut, PyResult, Python,
FromPyObject, PyAny, PyClass, PyErr, PyRef, PyRefMut, PyResult, Python,
};
use std::ops::Deref;

/// A trait which is used to help PyO3 macros extract function arguments.
///
Expand Down Expand Up @@ -694,26 +693,6 @@ fn push_parameter_list(msg: &mut String, parameter_names: &[&str]) {
}
}

pub trait FromRef<'a, T> {
fn from_ref(py_ref: &'a T) -> Self;
}

impl<'a, T> FromRef<'a, T> for &'a T {
fn from_ref(py_ref: &'a T) -> Self {
py_ref
}
}

impl<'a, T> FromRef<'a, T> for Py<T>
where
T: Deref<Target = PyAny> + 'a,
&'a T: IntoPy<Py<T>>,
{
fn from_ref(py_ref: &'a T) -> Self {
py_ref.into_py(py_ref.py())
}
}

#[cfg(test)]
mod tests {
use crate::{
Expand Down

0 comments on commit 9a82505

Please sign in to comment.