2020-08-29 07:25:20 +00:00
|
|
|
//! Testing https://github.com/PyO3/pyo3/issues/1106. A result type that
|
|
|
|
//! *doesn't* implement `From<MyError> for PyErr` won't be automatically
|
|
|
|
//! converted when using `#[pyfunction]`.
|
|
|
|
use pyo3::prelude::*;
|
|
|
|
|
|
|
|
use std::fmt;
|
|
|
|
|
|
|
|
/// A basic error type for the tests. It's missing `From<MyError> for PyErr`,
|
|
|
|
/// though, so it shouldn't work.
|
|
|
|
#[derive(Debug)]
|
|
|
|
struct MyError {
|
|
|
|
pub descr: &'static str,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for MyError {
|
2022-03-23 07:07:28 +00:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2020-08-29 07:25:20 +00:00
|
|
|
write!(f, "My error message: {}", self.descr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[pyfunction]
|
|
|
|
fn should_not_work() -> Result<(), MyError> {
|
2024-03-12 22:57:03 +00:00
|
|
|
Err(MyError {
|
|
|
|
descr: "something went wrong",
|
|
|
|
})
|
2020-08-29 07:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2024-03-12 22:57:03 +00:00
|
|
|
Python::with_gil(|py| {
|
|
|
|
wrap_pyfunction_bound!(should_not_work)(py);
|
2022-08-15 01:34:47 +00:00
|
|
|
});
|
2020-08-29 07:25:20 +00:00
|
|
|
}
|