[][src]Macro pyo3::import_exception

macro_rules! import_exception {
    ($module: expr, $name: ident) => { ... };
}

Defines a Rust type for an exception defined in Python code.

Syntax

import_exception!(module, MyError)

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();
}