-
Notifications
You must be signed in to change notification settings - Fork 802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add anyhow-integration
feature which implements From<anyhow::Error> for PyErr
#1822
Changes from 4 commits
948f9b6
58c3e89
d5313c5
defc2dd
f12db7f
3650516
5297969
1aa3d3d
a46f11e
99caed7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use crate::exceptions::PyRuntimeError; | ||
use crate::PyErr; | ||
|
||
impl From<anyhow::Error> for PyErr { | ||
fn from(err: anyhow::Error) -> Self { | ||
PyRuntimeError::new_err(format!("{:?}", err)) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test_anyhow { | ||
use crate::proc_macro::pyfunction; | ||
use crate::py_run; | ||
use crate::wrap_pyfunction; | ||
use crate::{Python, ToPyObject}; | ||
|
||
#[pyfunction] | ||
fn produce_ok_result() -> anyhow::Result<String> { | ||
Ok(String::from("OK buddy")) | ||
} | ||
|
||
#[pyfunction] | ||
fn produce_err_result() -> anyhow::Result<String> { | ||
anyhow::bail!("error time") | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's actually not ideal to use The point here is that it's probably better to just test that (If you really want to check the |
||
|
||
#[test] | ||
fn test_anyhow_py_function_ok_result() { | ||
Python::with_gil(|py| { | ||
let func = wrap_pyfunction!(produce_ok_result)(py).unwrap(); | ||
|
||
py_run!( | ||
py, | ||
func, | ||
r#" | ||
func() | ||
"# | ||
); | ||
}); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,5 @@ mod array; | |
pub mod indexmap; | ||
mod osstr; | ||
mod path; | ||
#[cfg(feature = "anyhow")] | ||
pub mod anyhow; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's put this in the
Packaging
section too and make sure this and theeyre
entry are written the same way?