From 5e0793e9ea7e17411c2e17578f3cadaba0716c9b Mon Sep 17 00:00:00 2001 From: Icxolu <10486322+Icxolu@users.noreply.github.com> Date: Sat, 16 Mar 2024 19:35:40 +0100 Subject: [PATCH] convert `TypeError` --- src/array.rs | 2 +- src/error.rs | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/array.rs b/src/array.rs index c4a1c9539..11a119371 100644 --- a/src/array.rs +++ b/src/array.rs @@ -281,7 +281,7 @@ impl PyArray { let src_dtype = array.dtype(); let dst_dtype = T::get_dtype_bound(ob.py()); if !src_dtype.is_equiv_to(&dst_dtype) { - return Err(TypeError::new(src_dtype.into_gil_ref(), dst_dtype.into_gil_ref()).into()); + return Err(TypeError::new(src_dtype, dst_dtype).into()); } Ok(array) diff --git a/src/error.rs b/src/error.rs index 1d7b3a20a..26b91fef6 100644 --- a/src/error.rs +++ b/src/error.rs @@ -3,7 +3,9 @@ use std::error::Error; use std::fmt; -use pyo3::{exceptions::PyTypeError, Py, PyErr, PyErrArguments, PyObject, Python, ToPyObject}; +use pyo3::{ + exceptions::PyTypeError, Bound, Py, PyErr, PyErrArguments, PyObject, Python, ToPyObject, +}; use crate::dtype::PyArrayDescr; @@ -59,13 +61,13 @@ impl_pyerr!(DimensionalityError); /// Represents that types of the given arrays do not match. #[derive(Debug)] -pub struct TypeError<'a> { - from: &'a PyArrayDescr, - to: &'a PyArrayDescr, +pub struct TypeError<'py> { + from: Bound<'py, PyArrayDescr>, + to: Bound<'py, PyArrayDescr>, } -impl<'a> TypeError<'a> { - pub(crate) fn new(from: &'a PyArrayDescr, to: &'a PyArrayDescr) -> Self { +impl<'py> TypeError<'py> { + pub(crate) fn new(from: Bound<'py, PyArrayDescr>, to: Bound<'py, PyArrayDescr>) -> Self { Self { from, to } } } @@ -86,8 +88,8 @@ struct TypeErrorArguments { impl PyErrArguments for TypeErrorArguments { fn arguments<'py>(self, py: Python<'py>) -> PyObject { let err = TypeError { - from: self.from.as_ref(py), - to: self.to.as_ref(py), + from: self.from.into_bound(py), + to: self.to.into_bound(py), }; err.to_string().to_object(py)