// TODO https://github.com/PyO3/pyo3/issues/5487 #![allow(clippy::undocumented_unsafe_blocks)] use crate::{Bound, PyAny, PyResult, PyTypeCheck}; pub(crate) trait PyResultExt<'py>: crate::sealed::Sealed { fn cast_into(self) -> PyResult>; unsafe fn cast_into_unchecked(self) -> PyResult>; } impl<'py> PyResultExt<'py> for PyResult> { #[inline] fn cast_into(self) -> PyResult> where { self.and_then(|instance| instance.cast_into().map_err(Into::into)) } #[inline] unsafe fn cast_into_unchecked(self) -> PyResult> { self.map(|instance| unsafe { instance.cast_into_unchecked() }) } }