Struct pyo3::PyErr

source ·
pub struct PyErr { /* private fields */ }
Expand description

Represents a Python exception.

Python exceptions can be raised in a “lazy” fashion, where the full Python object for the exception is not created until needed. The process of creating the full object is known as “normalization”. An exception which has not yet been created is known as “unnormalized”.

This struct builds upon that design, supporting all lazily-created Python exceptions and also supporting exceptions lazily-created from Rust.

Implementations§

source§

impl PyErr

source

pub fn new<T, A>(args: A) -> PyErrwhere T: PyTypeInfo, A: PyErrArguments + Send + Sync + 'static,

Creates a new PyErr of type T.

args can be:

  • a tuple: the exception instance will be created using the equivalent to the Python expression T(*tuple)
  • any other value: the exception instance will be created using the equivalent to the Python expression T(value)

This error will be stored in an unnormalized state. This avoids the need for the Python GIL to be held, but requires args to be Send and Sync. If args is not Send or Sync, consider using PyErr::from_value instead.

If an error occurs during normalization (for example if T is not a Python type which extends from BaseException), then a different error may be produced during normalization.

Examples
use pyo3::prelude::*;
use pyo3::exceptions::PyTypeError;

#[pyfunction]
fn always_throws() -> PyResult<()> {
    Err(PyErr::new::<PyTypeError, _>("Error message"))
}

In most cases, you can use a concrete exception’s constructor instead:

use pyo3::prelude::*;
use pyo3::exceptions::PyTypeError;

#[pyfunction]
fn always_throws() -> PyResult<()> {
    Err(PyTypeError::new_err("Error message"))
}
source

pub fn from_type<A>(ty: &PyType, args: A) -> PyErrwhere A: PyErrArguments + Send + Sync + 'static,

Constructs a new PyErr from the given Python type and arguments.

ty is the exception type; usually one of the standard exceptions like exceptions::PyRuntimeError.

args is either a tuple or a single value, with the same meaning as in PyErr::new.

If an error occurs during normalization (for example if T is not a Python type which extends from BaseException), then a different error may be produced during normalization.

This error will be stored in an unnormalized state.

source

pub fn from_value(obj: &PyAny) -> PyErr

Creates a new PyErr.

If obj is a Python exception object, the PyErr will contain that object. The error will be in a normalized state.

If obj is a Python exception type object, this is equivalent to PyErr::from_type(obj, ()).

Otherwise, a TypeError is created.

Examples
use pyo3::prelude::*;
use pyo3::exceptions::PyTypeError;
use pyo3::types::{PyType, PyString};

Python::with_gil(|py| {
    // Case #1: Exception object
    let err = PyErr::from_value(PyTypeError::new_err("some type error").value(py));
    assert_eq!(err.to_string(), "TypeError: some type error");

    // Case #2: Exception type
    let err = PyErr::from_value(PyType::new::<PyTypeError>(py));
    assert_eq!(err.to_string(), "TypeError: ");

    // Case #3: Invalid exception value
    let err = PyErr::from_value(PyString::new(py, "foo").into());
    assert_eq!(
        err.to_string(),
        "TypeError: exceptions must derive from BaseException"
    );
});
source

pub fn get_type<'py>(&'py self, py: Python<'py>) -> &'py PyType

Returns the type of this exception.

The object will be normalized first if needed.

Examples
use pyo3::{exceptions::PyTypeError, types::PyType, PyErr, Python};

Python::with_gil(|py| {
    let err: PyErr = PyTypeError::new_err(("some type error",));
    assert!(err.get_type(py).is(PyType::new::<PyTypeError>(py)));
});
source

pub fn value<'py>(&'py self, py: Python<'py>) -> &'py PyBaseException

Returns the value of this exception.

The object will be normalized first if needed.

Examples
use pyo3::{exceptions::PyTypeError, PyErr, Python};

Python::with_gil(|py| {
    let err: PyErr = PyTypeError::new_err(("some type error",));
    assert!(err.is_instance_of::<PyTypeError>(py));
    assert_eq!(err.value(py).to_string(), "some type error");
});
source

pub fn into_value(self, py: Python<'_>) -> Py<PyBaseException>

Consumes self to take ownership of the exception value contained in this error.

source

pub fn traceback<'py>(&'py self, py: Python<'py>) -> Option<&'py PyTraceback>

Returns the traceback of this exception object.

The object will be normalized first if needed.

Examples
use pyo3::{exceptions::PyTypeError, Python};

Python::with_gil(|py| {
    let err = PyTypeError::new_err(("some type error",));
    assert!(err.traceback(py).is_none());
});
source

pub fn occurred(_: Python<'_>) -> bool

Gets whether an error is present in the Python interpreter’s global state.

source

pub fn take(py: Python<'_>) -> Option<PyErr>

Takes the current error from the Python interpreter’s global state and clears the global state. If no error is set, returns None.

If the error is a PanicException (which would have originated from a panic in a pyo3 callback) then this function will resume the panic.

Use this function when it is not known if an error should be present. If the error is expected to have been set, for example from PyErr::occurred or by an error return value from a C FFI function, use PyErr::fetch.

source

pub fn fetch(py: Python<'_>) -> PyErr

Equivalent to PyErr::take, but when no error is set:

  • Panics in debug mode.
  • Returns a SystemError in release mode.

This behavior is consistent with Python’s internal handling of what happens when a C return value indicates an error occurred but the global error state is empty. (A lack of exception should be treated as a bug in the code which returned an error code but did not set an exception.)

Use this function when the error is expected to have been set, for example from PyErr::occurred or by an error return value from a C FFI function.

source

pub fn new_type( py: Python<'_>, name: &str, doc: Option<&str>, base: Option<&PyType>, dict: Option<PyObject> ) -> PyResult<Py<PyType>>

Creates a new exception type with the given name and docstring.

  • base can be an existing exception type to subclass, or a tuple of classes.
  • dict specifies an optional dictionary of class variables and methods.
  • doc will be the docstring seen by python users.
Errors

This function returns an error if name is not of the form <module>.<ExceptionName>.

Panics

This function will panic if name or doc cannot be converted to CStrings.

source

pub fn print(&self, py: Python<'_>)

Prints a standard traceback to sys.stderr.

source

pub fn print_and_set_sys_last_vars(&self, py: Python<'_>)

Prints a standard traceback to sys.stderr, and sets sys.last_{type,value,traceback} attributes to this exception’s data.

source

pub fn matches<T>(&self, py: Python<'_>, exc: T) -> boolwhere T: ToPyObject,

Returns true if the current exception matches the exception in exc.

If exc is a class object, this also returns true when self is an instance of a subclass. If exc is a tuple, all exceptions in the tuple (and recursively in subtuples) are searched for a match.

source

pub fn is_instance(&self, py: Python<'_>, ty: &PyAny) -> bool

Returns true if the current exception is instance of T.

source

pub fn is_instance_of<T>(&self, py: Python<'_>) -> boolwhere T: PyTypeInfo,

Returns true if the current exception is instance of T.

source

pub fn restore(self, py: Python<'_>)

Writes the error back to the Python interpreter’s global state. This is the opposite of PyErr::fetch().

source

pub fn write_unraisable(self, py: Python<'_>, obj: Option<&PyAny>)

Reports the error as unraisable.

This calls sys.unraisablehook() using the current exception and obj argument.

This method is useful to report errors in situations where there is no good mechanism to report back to the Python land. In Python this is used to indicate errors in background threads or destructors which are protected. In Rust code this is commonly useful when you are calling into a Python callback which might fail, but there is no obvious way to handle this error other than logging it.

Calling this method has the benefit that the error goes back into a standardized callback in Python which for instance allows unittests to ensure that no unraisable error actually happend by hooking sys.unraisablehook.

Example:

Python::with_gil(|py| {
    match failing_function() {
        Err(pyerr) => pyerr.write_unraisable(py, None),
        Ok(..) => { /* do something here */ }
    }
    Ok(())
})
source

pub fn warn( py: Python<'_>, category: &PyAny, message: &str, stacklevel: i32 ) -> PyResult<()>

Issues a warning message.

May return an Err(PyErr) if warnings-as-errors is enabled.

Equivalent to warnings.warn() in Python.

The category should be one of the Warning classes available in pyo3::exceptions, or a subclass. The Python object can be retrieved using Python::get_type().

Example:

Python::with_gil(|py| {
    let user_warning = py.get_type::<pyo3::exceptions::PyUserWarning>();
    PyErr::warn(py, user_warning, "I am warning you", 0)?;
    Ok(())
})
source

pub fn warn_explicit( py: Python<'_>, category: &PyAny, message: &str, filename: &str, lineno: i32, module: Option<&str>, registry: Option<&PyAny> ) -> PyResult<()>

Issues a warning message, with more control over the warning attributes.

May return a PyErr if warnings-as-errors is enabled.

Equivalent to warnings.warn_explicit() in Python.

The category should be one of the Warning classes available in pyo3::exceptions, or a subclass.

source

pub fn clone_ref(&self, py: Python<'_>) -> PyErr

Clone the PyErr. This requires the GIL, which is why PyErr does not implement Clone.

Examples
use pyo3::{exceptions::PyTypeError, PyErr, Python};
Python::with_gil(|py| {
    let err: PyErr = PyTypeError::new_err(("some type error",));
    let err_clone = err.clone_ref(py);
    assert!(err.get_type(py).is(err_clone.get_type(py)));
    assert!(err.value(py).is(err_clone.value(py)));
    match err.traceback(py) {
        None => assert!(err_clone.traceback(py).is_none()),
        Some(tb) => assert!(err_clone.traceback(py).unwrap().is(tb)),
    }
});
source

pub fn cause(&self, py: Python<'_>) -> Option<PyErr>

Return the cause (either an exception instance, or None, set by raise ... from ...) associated with the exception, as accessible from Python through __cause__.

source

pub fn set_cause(&self, py: Python<'_>, cause: Option<Self>)

Set the cause associated with the exception, pass None to clear it.

Trait Implementations§

source§

impl Debug for PyErr

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl Display for PyErr

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Error for PyErr

1.30.0 · source§

fn source(&self) -> Option<&(dyn Error + 'static)>

The lower-level source of this error, if any. Read more
1.0.0 · source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
source§

fn provide<'a>(&'a self, demand: &mut Demand<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type based access to context intended for error reports. Read more
source§

impl From<&CancelledError> for PyErr

source§

fn from(err: &CancelledError) -> PyErr

Converts to this type from the input type.
source§

impl From<&IncompleteReadError> for PyErr

source§

fn from(err: &IncompleteReadError) -> PyErr

Converts to this type from the input type.
source§

impl From<&InvalidStateError> for PyErr

source§

fn from(err: &InvalidStateError) -> PyErr

Converts to this type from the input type.
source§

impl From<&LimitOverrunError> for PyErr

source§

fn from(err: &LimitOverrunError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PanicException> for PyErr

source§

fn from(err: &PanicException) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyArithmeticError> for PyErr

source§

fn from(err: &PyArithmeticError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyAssertionError> for PyErr

source§

fn from(err: &PyAssertionError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyAttributeError> for PyErr

source§

fn from(err: &PyAttributeError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyBaseException> for PyErr

source§

fn from(err: &PyBaseException) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyBlockingIOError> for PyErr

source§

fn from(err: &PyBlockingIOError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyBrokenPipeError> for PyErr

source§

fn from(err: &PyBrokenPipeError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyBufferError> for PyErr

source§

fn from(err: &PyBufferError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyBytesWarning> for PyErr

source§

fn from(err: &PyBytesWarning) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyChildProcessError> for PyErr

source§

fn from(err: &PyChildProcessError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyConnectionAbortedError> for PyErr

source§

fn from(err: &PyConnectionAbortedError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyConnectionError> for PyErr

source§

fn from(err: &PyConnectionError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyConnectionRefusedError> for PyErr

source§

fn from(err: &PyConnectionRefusedError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyConnectionResetError> for PyErr

source§

fn from(err: &PyConnectionResetError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyDeprecationWarning> for PyErr

source§

fn from(err: &PyDeprecationWarning) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyEOFError> for PyErr

source§

fn from(err: &PyEOFError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyEncodingWarning> for PyErr

source§

fn from(err: &PyEncodingWarning) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyEnvironmentError> for PyErr

source§

fn from(err: &PyEnvironmentError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyException> for PyErr

source§

fn from(err: &PyException) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyFileExistsError> for PyErr

source§

fn from(err: &PyFileExistsError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyFileNotFoundError> for PyErr

source§

fn from(err: &PyFileNotFoundError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyFloatingPointError> for PyErr

source§

fn from(err: &PyFloatingPointError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyFutureWarning> for PyErr

source§

fn from(err: &PyFutureWarning) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyGeneratorExit> for PyErr

source§

fn from(err: &PyGeneratorExit) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyIOError> for PyErr

source§

fn from(err: &PyIOError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyImportError> for PyErr

source§

fn from(err: &PyImportError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyImportWarning> for PyErr

source§

fn from(err: &PyImportWarning) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyIndexError> for PyErr

source§

fn from(err: &PyIndexError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyInterruptedError> for PyErr

source§

fn from(err: &PyInterruptedError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyIsADirectoryError> for PyErr

source§

fn from(err: &PyIsADirectoryError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyKeyError> for PyErr

source§

fn from(err: &PyKeyError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyKeyboardInterrupt> for PyErr

source§

fn from(err: &PyKeyboardInterrupt) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyLookupError> for PyErr

source§

fn from(err: &PyLookupError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyMemoryError> for PyErr

source§

fn from(err: &PyMemoryError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyModuleNotFoundError> for PyErr

source§

fn from(err: &PyModuleNotFoundError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyNameError> for PyErr

source§

fn from(err: &PyNameError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyNotADirectoryError> for PyErr

source§

fn from(err: &PyNotADirectoryError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyNotImplementedError> for PyErr

source§

fn from(err: &PyNotImplementedError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyOSError> for PyErr

source§

fn from(err: &PyOSError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyOverflowError> for PyErr

source§

fn from(err: &PyOverflowError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyPendingDeprecationWarning> for PyErr

source§

fn from(err: &PyPendingDeprecationWarning) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyPermissionError> for PyErr

source§

fn from(err: &PyPermissionError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyProcessLookupError> for PyErr

source§

fn from(err: &PyProcessLookupError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyRecursionError> for PyErr

source§

fn from(err: &PyRecursionError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyReferenceError> for PyErr

source§

fn from(err: &PyReferenceError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyResourceWarning> for PyErr

source§

fn from(err: &PyResourceWarning) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyRuntimeError> for PyErr

source§

fn from(err: &PyRuntimeError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyRuntimeWarning> for PyErr

source§

fn from(err: &PyRuntimeWarning) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyStopAsyncIteration> for PyErr

source§

fn from(err: &PyStopAsyncIteration) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyStopIteration> for PyErr

source§

fn from(err: &PyStopIteration) -> PyErr

Converts to this type from the input type.
source§

impl From<&PySyntaxError> for PyErr

source§

fn from(err: &PySyntaxError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PySyntaxWarning> for PyErr

source§

fn from(err: &PySyntaxWarning) -> PyErr

Converts to this type from the input type.
source§

impl From<&PySystemError> for PyErr

source§

fn from(err: &PySystemError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PySystemExit> for PyErr

source§

fn from(err: &PySystemExit) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyTimeoutError> for PyErr

source§

fn from(err: &PyTimeoutError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyTypeError> for PyErr

source§

fn from(err: &PyTypeError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyUnboundLocalError> for PyErr

source§

fn from(err: &PyUnboundLocalError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyUnicodeDecodeError> for PyErr

source§

fn from(err: &PyUnicodeDecodeError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyUnicodeEncodeError> for PyErr

source§

fn from(err: &PyUnicodeEncodeError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyUnicodeError> for PyErr

source§

fn from(err: &PyUnicodeError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyUnicodeTranslateError> for PyErr

source§

fn from(err: &PyUnicodeTranslateError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyUnicodeWarning> for PyErr

source§

fn from(err: &PyUnicodeWarning) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyUserWarning> for PyErr

source§

fn from(err: &PyUserWarning) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyValueError> for PyErr

source§

fn from(err: &PyValueError) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyWarning> for PyErr

source§

fn from(err: &PyWarning) -> PyErr

Converts to this type from the input type.
source§

impl From<&PyZeroDivisionError> for PyErr

source§

fn from(err: &PyZeroDivisionError) -> PyErr

Converts to this type from the input type.
source§

impl From<&QueueEmpty> for PyErr

source§

fn from(err: &QueueEmpty) -> PyErr

Converts to this type from the input type.
source§

impl From<&QueueFull> for PyErr

source§

fn from(err: &QueueFull) -> PyErr

Converts to this type from the input type.
source§

impl From<&TimeoutError> for PyErr

source§

fn from(err: &TimeoutError) -> PyErr

Converts to this type from the input type.
source§

impl From<&gaierror> for PyErr

source§

fn from(err: &gaierror) -> PyErr

Converts to this type from the input type.
source§

impl From<&herror> for PyErr

source§

fn from(err: &herror) -> PyErr

Converts to this type from the input type.
source§

impl From<&timeout> for PyErr

source§

fn from(err: &timeout) -> PyErr

Converts to this type from the input type.
source§

impl From<AddrParseError> for PyErr

source§

fn from(err: AddrParseError) -> PyErr

Converts to this type from the input type.
source§

impl From<DecodeUtf16Error> for PyErr

source§

fn from(err: DecodeUtf16Error) -> PyErr

Converts to this type from the input type.
source§

impl From<Error> for PyErr

Create OSError from io::Error

source§

fn from(err: Error) -> PyErr

Converts to this type from the input type.
source§

impl From<FromUtf16Error> for PyErr

source§

fn from(err: FromUtf16Error) -> PyErr

Converts to this type from the input type.
source§

impl From<FromUtf8Error> for PyErr

source§

fn from(err: FromUtf8Error) -> PyErr

Converts to this type from the input type.
source§

impl From<Infallible> for PyErr

source§

fn from(_: Infallible) -> PyErr

Converts to this type from the input type.
source§

impl<W: 'static + Send + Sync + Debug> From<IntoInnerError<W>> for PyErr

source§

fn from(err: IntoInnerError<W>) -> PyErr

Converts to this type from the input type.
source§

impl From<IntoStringError> for PyErr

source§

fn from(err: IntoStringError) -> PyErr

Converts to this type from the input type.
source§

impl From<NulError> for PyErr

source§

fn from(err: NulError) -> PyErr

Converts to this type from the input type.
source§

impl From<ParseBoolError> for PyErr

source§

fn from(err: ParseBoolError) -> PyErr

Converts to this type from the input type.
source§

impl From<ParseFloatError> for PyErr

source§

fn from(err: ParseFloatError) -> PyErr

Converts to this type from the input type.
source§

impl From<ParseIntError> for PyErr

source§

fn from(err: ParseIntError) -> PyErr

Converts to this type from the input type.
source§

impl From<PyBorrowError> for PyErr

source§

fn from(other: PyBorrowError) -> Self

Converts to this type from the input type.
source§

impl From<PyBorrowMutError> for PyErr

source§

fn from(other: PyBorrowMutError) -> Self

Converts to this type from the input type.
source§

impl<'a> From<PyDowncastError<'a>> for PyErr

Convert PyDowncastError to Python TypeError.

source§

fn from(err: PyDowncastError<'_>) -> PyErr

Converts to this type from the input type.
source§

impl From<PyErr> for Error

Convert PyErr to io::Error

source§

fn from(err: PyErr) -> Self

Converts to this type from the input type.
source§

impl From<Report> for PyErr

Available on crate feature eyre only.

Converts eyre::Report to a PyErr containing a PyRuntimeError.

If you want to raise a different Python exception you will have to do so manually. See PyErr::new for more information about that.

source§

fn from(error: Report) -> Self

Converts to this type from the input type.
source§

impl From<TryFromIntError> for PyErr

source§

fn from(err: TryFromIntError) -> PyErr

Converts to this type from the input type.
source§

impl From<TryFromSliceError> for PyErr

source§

fn from(err: TryFromSliceError) -> PyErr

Converts to this type from the input type.
source§

impl From<Utf8Error> for PyErr

source§

fn from(err: Utf8Error) -> PyErr

Converts to this type from the input type.
source§

impl<'a> IntoPy<Py<PyAny>> for &'a PyErr

source§

fn into_py(self, py: Python<'_>) -> PyObject

Performs the conversion.
source§

impl IntoPy<Py<PyAny>> for PyErr

source§

fn into_py(self, py: Python<'_>) -> PyObject

Performs the conversion.
source§

impl ToPyObject for PyErr

source§

fn to_object(&self, py: Python<'_>) -> PyObject

Converts self into a Python object.
source§

impl Send for PyErr

source§

impl Sync for PyErr

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<E> Provider for Ewhere E: Error + ?Sized,

source§

fn provide<'a>(&'a self, demand: &mut Demand<'a>)

🔬This is a nightly-only experimental API. (provide_any)
Data providers should implement this method to provide all values they are able to provide by using demand. Read more
source§

impl<T> ToBorrowedObject for Twhere T: ToPyObject,

source§

fn with_borrowed_ptr<F, R>(&self, py: Python<'_>, f: F) -> Rwhere F: FnOnce(*mut PyObject) -> R,

👎Deprecated since 0.17.0: this trait is no longer used by PyO3, use ToPyObject or IntoPy<PyObject>
Converts self into a Python object and calls the specified closure on the native FFI pointer underlying the Python object. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> Ungil for Twhere T: Send,