PyO3/pyo3

Add exceptions to modules

Offen

#732 geöffnet am 14.01.2020

 (9 Kommentare) (13 Reaktionen) (0 zugewiesene Personen)Rust (668 Forks)batch import
1.0-candidateGood First Issueneeds-design

Repository-Metriken

Stars
 (10.152 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 9T 18h) (51 gemergte PRs in 30 T)

Beschreibung

After creating a new exception using:

create_exception!(my_module, MyException, ExceptionClass);

It is natural that I would want to make it available as an import within my python module:

from my_module import MyException

However, in order to do this, I had to do some deep Kung Foo action:

#[pymodule]
fn my_module(py: Python, m: PyModule) {
    m.add("MyException", py.get_type::<MyException>())?;
}

It would be nice to have an easier API for this:

#[pymodule]
fn my_module(_py: Python, m: PyModule) {
    m.add_exception::<MyException>()?;
}

Contributor Guide