pub fn fetch(py: Python) -> Option<PyErr> {
        unsafe {
            let mut ptype: *mut ffi::PyObject = std::ptr::null_mut();
            let mut pvalue: *mut ffi::PyObject = std::ptr::null_mut();
            let mut ptraceback: *mut ffi::PyObject = std::ptr::null_mut();
            ffi::PyErr_Fetch(&mut ptype, &mut pvalue, &mut ptraceback);

            // If the error indicator is not set, all three variables are set to NULL
            if ptype.is_null() && pvalue.is_null() && ptraceback.is_null() {
                return None;
            }

            let err = PyErr::new_from_ffi_tuple(py, ptype, pvalue, ptraceback);

            if ptype == PanicException::type_object(py).as_ptr() {
                let msg: String = PyAny::from_borrowed_ptr_or_opt(py, pvalue)
                    .and_then(|obj| obj.extract().ok())
                    .unwrap_or_else(|| String::from("Unwrapped panic from Python code"));

                eprintln!(
                    "--- PyO3 is resuming a panic after fetching a PanicException from Python. ---"
                );
                eprintln!("Python stack trace below:");
                err.print(py);

                std::panic::resume_unwind(Box::new(msg))
            }

            Some(err)
        }
    }
/// Retrieves the current error from the Python interpreter's global state.
///
/// The error is cleared from the Python interpreter.
/// If no error is set, returns a `None`.
///
/// If the error fetched is a `PanicException` (which would have originated from a panic in a
/// pyo3 callback) then this function will resume the panic.
Retrieves the current error from the Python interpreter's global state.
The error is cleared from the Python interpreter.
If no error is set, returns a `None`.

If the error fetched is a `PanicException` (which would have originated from a panic in a
pyo3 callback) then this function will resume the panic.
Retrieves the current error from the Python interpreter ' s global state . The error is cleared from the Python interpreter . If no error is set returns a ` None ` . If the error fetched is a ` PanicException ` ( which would have originated from a panic in a pyo3 callback ) then this function will resume the panic .
pub fn fetch(py: Python) -> Option<PyErr> {
        unsafe {
            let mut ptype: *mut ffi::PyObject = std::ptr::null_mut();
            let mut pvalue: *mut ffi::PyObject = std::ptr::null_mut();
            let mut ptraceback: *mut ffi::PyObject = std::ptr::null_mut();
            ffi::PyErr_Fetch(&mut ptype, &mut pvalue, &mut ptraceback);
            // If the error indicator is not set, all three variables are set to NULL
            if ptype.is_null() && pvalue.is_null() && ptraceback.is_null() {
                return None;
            }
            let err = PyErr::new_from_ffi_tuple(py, ptype, pvalue, ptraceback);
            if ptype == PanicException::type_object(py).as_ptr() {
                let msg: String = PyAny::from_borrowed_ptr_or_opt(py, pvalue)
                    .and_then(|obj| obj.extract().ok())
                    .unwrap_or_else(|| String::from("Unwrapped panic from Python code"));
                eprintln!(
                    "--- PyO3 is resuming a panic after fetching a PanicException from Python. ---"
                );
                eprintln!("Python stack trace below:");
                err.print(py);
                std::panic::resume_unwind(Box::new(msg))
            }
            Some(err)
        }
    }
pub fn fetch ( py : Python ) -> Option < PyErr > { unsafe { let mut ptype : * mut ffi :: PyObject = std :: ptr :: null_mut ( ) ; let mut pvalue : * mut ffi :: PyObject = std :: ptr :: null_mut ( ) ; let mut ptraceback : * mut ffi :: PyObject = std :: ptr :: null_mut ( ) ; ffi :: PyErr_Fetch ( & mut ptype , & mut pvalue , & mut ptraceback ) ; // If the error indicator is not set, all three variables are set to NULL if ptype . is_null ( ) && pvalue . is_null ( ) && ptraceback . is_null ( ) { return None ; } let err = PyErr :: new_from_ffi_tuple ( py , ptype , pvalue , ptraceback ) ; if ptype == PanicException :: type_object ( py ) . as_ptr ( ) { let msg : String = PyAny :: from_borrowed_ptr_or_opt ( py , pvalue ) . and_then ( | obj | obj . extract ( ) . ok ( ) ) . unwrap_or_else ( | | String :: from ( " " ) ) ; eprintln ! ( " " ) ; eprintln ! ( " " ) ; err . print ( py ) ; std :: panic :: resume_unwind ( Box :: new ( msg ) ) } Some ( err ) } }
Retrieves the current error from the Python interpreter's global state.
Retrieves the current error from the Python interpreter ' s global state .
py
Python