Open
Description
I would be great to have a custom derive for exceptions, similar but more powerful than create_exception. This would e.g. allow reimplementing JSONDecodeError
:
#[pyexception(module = json)]
struct JSONDecodeError {
msg: String,
doc: String,
pos: usize,
lineno: Option<usize>,
colno: Option<usize>,
}
The steps required are roughly:
- Look at examples in syn and pyo3's existing proc macros to learn how to implement a proc macro. wasm-bindgen could be another useful resource.
- Implement the macro using the existing impl_exception_boilerplate and create_exception_type_object macros. The
#[proc_macro_attribute]
function should go inpyo3cls/src/lib.rs
, while the actual implementation should be inpyo3-derive-backend
. - Write tests. Most important is one for a struct without members and one with at least 2 members.
- Add a usage example to the guide. You can just copy one of the tests for that.
If you want to work on implementing this or have any questions, feel free ask here or on gitter!