ee89b2e8e2
* deprecate `wrap_pyfunction` with `py` argument The Python token in `wrap_pyfunction` is not handled automatically by `WrapPyFunctionArg`, for backwards compatibility. This uses deref specialization to deprecate this variant. * merge `Extractor`s * add deprecation ui test, revert closure variant due to test failure * fix nightly
33 lines
792 B
Rust
33 lines
792 B
Rust
//! 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 {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
write!(f, "My error message: {}", self.descr)
|
|
}
|
|
}
|
|
|
|
#[pyfunction]
|
|
fn should_not_work() -> Result<(), MyError> {
|
|
Err(MyError {
|
|
descr: "something went wrong",
|
|
})
|
|
}
|
|
|
|
fn main() {
|
|
Python::with_gil(|py| {
|
|
wrap_pyfunction_bound!(should_not_work)(py);
|
|
});
|
|
}
|