Merge pull request #506 from PyO3/more_error_information

Print error before on class init panic
This commit is contained in:
Yuji Kanagawa 2019-06-14 14:16:47 +09:00 committed by GitHub
commit 05b0cb66f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 7 additions and 6 deletions

View File

@ -20,8 +20,8 @@ use std::os::raw::c_char;
pub enum PyErrValue {
None,
Value(PyObject),
ToArgs(Box<PyErrArguments>),
ToObject(Box<ToPyObject>),
ToArgs(Box<dyn PyErrArguments>),
ToObject(Box<dyn ToPyObject>),
}
/// Represents a Python exception that was raised.

View File

@ -123,7 +123,7 @@ struct ReleasePool {
owned: ArrayList<NonNull<ffi::PyObject>>,
borrowed: ArrayList<NonNull<ffi::PyObject>>,
pointers: *mut Vec<NonNull<ffi::PyObject>>,
obj: Vec<Box<any::Any>>,
obj: Vec<Box<dyn any::Any>>,
p: spin::Mutex<*mut Vec<NonNull<ffi::PyObject>>>,
}

View File

@ -259,7 +259,8 @@ where
let gil = Python::acquire_gil();
let py = gil.python();
initialize_type::<Self>(py, <Self as PyTypeInfo>::MODULE).unwrap_or_else(|_| {
initialize_type::<Self>(py, <Self as PyTypeInfo>::MODULE).unwrap_or_else(|e| {
e.print(py);
panic!("An error occurred while initializing class {}", Self::NAME)
});
}

View File

@ -192,7 +192,7 @@ impl PyModule {
/// ```rust,ignore
/// m.add("also_double", wrap_pyfunction!(double)(py));
/// ```
pub fn add_wrapped(&self, wrapper: &Fn(Python) -> PyObject) -> PyResult<()> {
pub fn add_wrapped(&self, wrapper: &impl Fn(Python) -> PyObject) -> PyResult<()> {
let function = wrapper(self.py());
let name = function
.getattr(self.py(), "__name__")

View File

@ -49,7 +49,7 @@ fn len() {
#[pyclass]
struct Iterator {
iter: Box<iter::Iterator<Item = i32> + Send>,
iter: Box<dyn iter::Iterator<Item = i32> + Send>,
}
#[pyproto]