Macro pyo3::import_exception
[−]
[src]
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
#![feature(const_fn, const_ptr_null_mut)] #[macro_use] extern crate pyo3; use pyo3::{Python, 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(); }