[][src]Macro pyo3::import_exception

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

Defines rust type for 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

#[macro_use] extern crate pyo3;

use pyo3::Python;
use pyo3::types::PyDict;

import_exception!(socket, gaierror);

fn main() {
    let gil = Python::acquire_gil();
    let py = gil.python();
    let ctx = PyDict::new(py);

    ctx.set_item("gaierror", py.get_type::<gaierror>()).unwrap();
    py.run("import socket; assert gaierror is socket.gaierror", None, Some(ctx)).unwrap();
}