diff --git a/src/types/tuple.rs b/src/types/tuple.rs index 711922ce3fa..44a9d15e836 100644 --- a/src/types/tuple.rs +++ b/src/types/tuple.rs @@ -1,5 +1,6 @@ use std::iter::FusedIterator; +use crate::conversion::IntoPyObject; use crate::ffi::{self, Py_ssize_t}; use crate::ffi_ptr_ext::FfiPtrExt; #[cfg(feature = "experimental-inspect")] @@ -8,8 +9,8 @@ use crate::instance::Borrowed; use crate::internal_tricks::get_ssize_index; use crate::types::{any::PyAnyMethods, sequence::PySequenceMethods, PyList, PySequence}; use crate::{ - exceptions, Bound, FromPyObject, IntoPy, Py, PyAny, PyErr, PyObject, PyResult, Python, - ToPyObject, + exceptions, Bound, BoundObject, FromPyObject, IntoPy, Py, PyAny, PyErr, PyObject, PyResult, + Python, ToPyObject, }; #[inline] @@ -526,6 +527,20 @@ fn type_output() -> TypeInfo { } } + impl <'py, $($T),+> IntoPyObject<'py> for ($($T,)+) + where + $($T: IntoPyObject<'py>,)+ + PyErr: $(From<$T::Error> + )+ + { + type Target = PyTuple; + type Output = Bound<'py, Self::Target>; + type Error = PyErr; + + fn into_pyobject(self, py: Python<'py>) -> Result { + Ok(array_into_tuple(py, [$(self.$n.into_pyobject(py)?.into_any().unbind()),+]).into_bound(py)) + } + } + impl <$($T: IntoPy),+> IntoPy> for ($($T,)+) { fn into_py(self, py: Python<'_>) -> Py { array_into_tuple(py, [$(self.$n.into_py(py)),+])