Skip to content

Commit 481fcaf

Browse files
committed
Replace PyErr::from_value_bound calls with .into
1 parent 3fd8f6b commit 481fcaf

File tree

5 files changed

+22
-28
lines changed

5 files changed

+22
-28
lines changed

src/coroutine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl Coroutine {
7878
(Some(exc), Some(cb)) => cb.throw(exc),
7979
(Some(exc), None) => {
8080
self.close();
81-
return Err(PyErr::from_value_bound(exc.into_bound(py)));
81+
return Err(exc.into_bound(py).into());
8282
}
8383
(None, _) => {}
8484
}

src/exceptions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ mod tests {
10721072
);
10731073

10741074
// Restoring should preserve the same error
1075-
let e = PyErr::from_value_bound(decode_err.into_any());
1075+
let e: PyErr = decode_err.into();
10761076
e.restore(py);
10771077

10781078
assert_eq!(

src/tests/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ mod inner {
7474
#[pymethods(crate = "pyo3")]
7575
impl UnraisableCapture {
7676
pub fn hook(&mut self, unraisable: Bound<'_, PyAny>) {
77-
let err = PyErr::from_value_bound(unraisable.getattr("exc_value").unwrap());
77+
let err = unraisable.getattr("exc_value").unwrap();
7878
let instance = unraisable.getattr("object").unwrap();
79-
self.capture = Some((err, instance.into()));
79+
self.capture = Some((err.into(), instance.into()));
8080
}
8181
}
8282

src/types/string.rs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -73,40 +73,34 @@ impl<'a> PyStringData<'a> {
7373
match self {
7474
Self::Ucs1(data) => match str::from_utf8(data) {
7575
Ok(s) => Ok(Cow::Borrowed(s)),
76-
Err(e) => Err(crate::PyErr::from_value_bound(
77-
PyUnicodeDecodeError::new_utf8_bound(py, data, e)?.into_any(),
78-
)),
76+
Err(e) => Err(PyUnicodeDecodeError::new_utf8_bound(py, data, e)?.into()),
7977
},
8078
Self::Ucs2(data) => match String::from_utf16(data) {
8179
Ok(s) => Ok(Cow::Owned(s)),
8280
Err(e) => {
8381
let mut message = e.to_string().as_bytes().to_vec();
8482
message.push(0);
8583

86-
Err(crate::PyErr::from_value_bound(
87-
PyUnicodeDecodeError::new_bound(
88-
py,
89-
CStr::from_bytes_with_nul(b"utf-16\0").unwrap(),
90-
self.as_bytes(),
91-
0..self.as_bytes().len(),
92-
CStr::from_bytes_with_nul(&message).unwrap(),
93-
)?
94-
.into_any(),
95-
))
96-
}
97-
},
98-
Self::Ucs4(data) => match data.iter().map(|&c| std::char::from_u32(c)).collect() {
99-
Some(s) => Ok(Cow::Owned(s)),
100-
None => Err(crate::PyErr::from_value_bound(
101-
PyUnicodeDecodeError::new_bound(
84+
Err(PyUnicodeDecodeError::new_bound(
10285
py,
103-
CStr::from_bytes_with_nul(b"utf-32\0").unwrap(),
86+
CStr::from_bytes_with_nul(b"utf-16\0").unwrap(),
10487
self.as_bytes(),
10588
0..self.as_bytes().len(),
106-
CStr::from_bytes_with_nul(b"error converting utf-32\0").unwrap(),
89+
CStr::from_bytes_with_nul(&message).unwrap(),
10790
)?
108-
.into_any(),
109-
)),
91+
.into())
92+
}
93+
},
94+
Self::Ucs4(data) => match data.iter().map(|&c| std::char::from_u32(c)).collect() {
95+
Some(s) => Ok(Cow::Owned(s)),
96+
None => Err(PyUnicodeDecodeError::new_bound(
97+
py,
98+
CStr::from_bytes_with_nul(b"utf-32\0").unwrap(),
99+
self.as_bytes(),
100+
0..self.as_bytes().len(),
101+
CStr::from_bytes_with_nul(b"error converting utf-32\0").unwrap(),
102+
)?
103+
.into()),
110104
},
111105
}
112106
}

src/types/traceback.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ except Exception as e:
147147
Some(&locals),
148148
)
149149
.unwrap();
150-
let err = PyErr::from_value_bound(locals.get_item("err").unwrap().unwrap());
150+
let err: PyErr = locals.get_item("err").unwrap().unwrap().into();
151151
let traceback = err.value_bound(py).getattr("__traceback__").unwrap();
152152
assert!(err.traceback_bound(py).unwrap().is(&traceback));
153153
})

0 commit comments

Comments
 (0)