cpython-ext: rename fallible to anyhow_result

Summary: We no longer use the `failure` crate. Rename related methods and traits.

Reviewed By: markbt

Differential Revision: D19186694

fbshipit-source-id: 1c83a90ee12db431b7d8e09a9c2cf1d43a4c0f93
This commit is contained in:
Jun Wu 2019-12-20 16:09:56 -08:00 committed by Facebook Github Bot
parent ef3f9b932d
commit d4a19306ed
3 changed files with 15 additions and 15 deletions

View File

@ -9,7 +9,7 @@
use anyhow::Error;
use cpython::*;
use cpython_ext::{FallibleExt, ResultPyErrExt};
use cpython_ext::{AnyhowResultExt, ResultPyErrExt};
use dag::{
id::{Group, Id},
idmap::IdMap,
@ -343,13 +343,13 @@ fn translate_get_parents<'a>(
move |node: &[u8]| -> Result<Vec<Box<[u8]>>> {
let mut result = Vec::new();
let node = PyBytes::new(py, node);
let parents = get_parents.call(py, (node,), None).into_fallible()?;
for parent in parents.iter(py).into_fallible()? {
let parents = get_parents.call(py, (node,), None).into_anyhow_result()?;
for parent in parents.iter(py).into_anyhow_result()? {
let parent = parent
.into_fallible()?
.into_anyhow_result()?
.cast_as::<PyBytes>(py)
.map_err(PyErr::from)
.into_fallible()?
.into_anyhow_result()?
.data(py)
.to_vec()
.into_boxed_slice();

View File

@ -16,7 +16,7 @@ use std::fmt;
/// Extends the `Result` type to allow conversion to `PyResult` from a native
/// Rust result.
///
/// If the error is created via [`FallibleExt`], the original Python error
/// If the error is created via [`AnyhowResultExt`], the original Python error
/// will be returned.
///
/// # Examples
@ -48,26 +48,26 @@ pub trait ResultPyErrExt<T> {
///
/// ```
/// use anyhow::Result;
/// use cpython_ext::error::{FallibleExt, PyErr};
/// use cpython_ext::error::{AnyhowResultExt, PyErr};
///
/// fn eval_py() -> Result<i32> {
/// let gil = cpython::Python::acquire_gil();
/// let py = gil.python();
/// let obj = py.eval("1 + 2", None, None).into_fallible()?;
/// obj.extract(py).into_fallible()
/// let obj = py.eval("1 + 2", None, None).into_anyhow_result()?;
/// obj.extract(py).into_anyhow_result()
/// }
///
/// fn round_trip() -> cpython::PyResult<()> {
/// let gil = cpython::Python::acquire_gil();
/// let py = gil.python();
/// let res = py.eval("1 + 2", None, None).into_fallible();
/// let res = py.eval("1 + 2", None, None).into_anyhow_result();
/// use cpython_ext::error::ResultPyErrExt;
/// res.map(|_| ()).map_pyerr(py)
/// }
/// ```
///
pub trait FallibleExt<T> {
fn into_fallible(self) -> Result<T>;
pub trait AnyhowResultExt<T> {
fn into_anyhow_result(self) -> Result<T>;
}
py_exception!(error, PyIndexedLogError);
@ -98,8 +98,8 @@ impl<T, E: Into<Error>> ResultPyErrExt<T> for Result<T, E> {
}
}
impl<T> FallibleExt<T> for PyResult<T> {
fn into_fallible(self) -> Result<T> {
impl<T> AnyhowResultExt<T> for PyResult<T> {
fn into_anyhow_result(self) -> Result<T> {
self.map_err(|e| Error::new(PyErr::from(e)))
}
}

View File

@ -16,7 +16,7 @@ pub mod ser;
pub use crate::bytearrayobject::{boxed_slice_to_pyobj, vec_to_pyobj};
pub use crate::bytesobject::allocate_pybytes;
pub use crate::error::{format_py_error, FallibleExt, PyErr, ResultPyErrExt};
pub use crate::error::{format_py_error, AnyhowResultExt, PyErr, ResultPyErrExt};
pub use crate::io::{wrap_pyio, WrappedIO};
pub use crate::pybuf::SimplePyBuf;
pub use crate::pyset::{pyset_add, pyset_new};