Skip to content

Commit ec0c4c4

Browse files
committed
convert TypeError
1 parent 0d78f47 commit ec0c4c4

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/array.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
281281
let src_dtype = array.dtype();
282282
let dst_dtype = T::get_dtype_bound(ob.py());
283283
if !src_dtype.is_equiv_to(&dst_dtype) {
284-
return Err(TypeError::new(src_dtype.into_gil_ref(), dst_dtype.into_gil_ref()).into());
284+
return Err(TypeError::new(src_dtype, dst_dtype).into());
285285
}
286286

287287
Ok(array)

src/error.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
use std::error::Error;
44
use std::fmt;
55

6-
use pyo3::{exceptions::PyTypeError, Py, PyErr, PyErrArguments, PyObject, Python, ToPyObject};
6+
use pyo3::{
7+
exceptions::PyTypeError, Bound, Py, PyErr, PyErrArguments, PyObject, Python, ToPyObject,
8+
};
79

810
use crate::dtype::PyArrayDescr;
911

@@ -59,13 +61,13 @@ impl_pyerr!(DimensionalityError);
5961

6062
/// Represents that types of the given arrays do not match.
6163
#[derive(Debug)]
62-
pub struct TypeError<'a> {
63-
from: &'a PyArrayDescr,
64-
to: &'a PyArrayDescr,
64+
pub struct TypeError<'py> {
65+
from: Bound<'py, PyArrayDescr>,
66+
to: Bound<'py, PyArrayDescr>,
6567
}
6668

67-
impl<'a> TypeError<'a> {
68-
pub(crate) fn new(from: &'a PyArrayDescr, to: &'a PyArrayDescr) -> Self {
69+
impl<'py> TypeError<'py> {
70+
pub(crate) fn new(from: Bound<'py, PyArrayDescr>, to: Bound<'py, PyArrayDescr>) -> Self {
6971
Self { from, to }
7072
}
7173
}
@@ -86,8 +88,8 @@ struct TypeErrorArguments {
8688
impl PyErrArguments for TypeErrorArguments {
8789
fn arguments<'py>(self, py: Python<'py>) -> PyObject {
8890
let err = TypeError {
89-
from: self.from.as_ref(py),
90-
to: self.to.as_ref(py),
91+
from: self.from.into_bound(py),
92+
to: self.to.into_bound(py),
9193
};
9294

9395
err.to_string().to_object(py)

0 commit comments

Comments
 (0)