Add a `#[pyo3]` macro
It would be great to have a single #[pyo3] macro like the #[wasm-bindgen] macro in wasm-bindgen. This macro would have the following properties:
- It can be attached to functions, classes,
impl $structandimpl $protocol for $struct. The macro can decide where it's attached to by usingsyn::parseinto asyn::Item, matching and delegating to the respective code gen function. - It supports the parameters currently supported (mostly by reusing the existing code)
- Method types (static, method, etc.) are automatically detected. The constructor might require a
#[pyo3(constructor)]annotation - There is
#[pyo3(module)]to replace#[pymodule]. It doesn't need to support#[pyfn]though since we can do freestanding functions now. - Tests for all features. This doesn't need to be as elaborate as wasm-bindgen, but maybe we can come up with something where we feed syn item to functions in
pyo3-derive-backend. (Integration tests are also sufficient)
The best was to get started is probably adding a function in pyo3cls/src/lib.rs that dispatches to the existing macros and then expanding upon that. Looking into capybara*s pyo3 wrapper and wasm bindgen's macro frontend should give some additional pointers.
I have been thinking about this and think it's a good idea. We also implemented attributes like #[name = "foo"] on #[pyclass], but in retrospect I think that might have been a mistake and should have been namespaced as #[pyo3(name = "foo)].
We might want to do a review of how much we can add in a non-breaking fashion already and then consider deprecating old names later.