From aade6ed95f920a2e6a2bc0cd0b91058af33c76c2 Mon Sep 17 00:00:00 2001 From: Icxolu <10486322+Icxolu@users.noreply.github.com> Date: Thu, 11 Jul 2024 21:30:55 +0200 Subject: [PATCH] loose type restrictions on `Either` impl --- src/conversions/either.rs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/conversions/either.rs b/src/conversions/either.rs index abd06333c70..6dad1751ff1 100644 --- a/src/conversions/either.rs +++ b/src/conversions/either.rs @@ -48,7 +48,7 @@ use crate::conversion::AnyBound; use crate::inspect::types::TypeInfo; use crate::{ conversion::IntoPyObject, exceptions::PyTypeError, types::any::PyAnyMethods, Bound, - FromPyObject, IntoPy, PyAny, PyObject, PyResult, Python, ToPyObject, + FromPyObject, IntoPy, PyAny, PyErr, PyObject, PyResult, Python, ToPyObject, }; use either::Either; @@ -68,20 +68,29 @@ where } #[cfg_attr(docsrs, doc(cfg(feature = "either")))] -impl<'py, L, R, T, E, O> IntoPyObject<'py> for Either +impl<'py, L, R, E1, E2> IntoPyObject<'py> for Either where - L: IntoPyObject<'py, Target = T, Error = E, Output = O>, - R: IntoPyObject<'py, Target = T, Error = E, Output = O>, - O: AnyBound<'py, T>, + L: IntoPyObject<'py, Error = E1>, + R: IntoPyObject<'py, Error = E2>, + E1: Into, + E2: Into, { - type Target = T; - type Output = O; - type Error = E; + type Target = PyAny; + type Output = Bound<'py, Self::Target>; + type Error = PyErr; fn into_pyobject(self, py: Python<'py>) -> Result { match self { - Either::Left(l) => l.into_pyobject(py), - Either::Right(r) => r.into_pyobject(py), + Either::Left(l) => l + .into_pyobject(py) + .map(AnyBound::into_any) + .map(AnyBound::into_bound) + .map_err(Into::into), + Either::Right(r) => r + .into_pyobject(py) + .map(AnyBound::into_any) + .map(AnyBound::into_bound) + .map_err(Into::into), } } }