[−][src]Macro pyo3::import_exception
Defines a Rust type for an exception defined in Python code.
Syntax
import_exception!(module, MyError)
module
is the name of the containing module.MyError
is the name of the new exception type.
Example
use pyo3::import_exception; use pyo3::types::IntoPyDict; use pyo3::Python; import_exception!(socket, gaierror); fn main() { let gil = Python::acquire_gil(); let py = gil.python(); let ctx = [("gaierror", py.get_type::<gaierror>())].into_py_dict(py); py.run( "import socket; assert gaierror is socket.gaierror", None, Some(ctx), ) .unwrap(); }