Add a `#[pyo3]` macro
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.2k
- Forks
- 1k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 66
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in pyo3cls/src/lib.rs and inspect the existing attribute macros and their code-generation paths. Read how syn::Item is used, then compare the capybara wrapper and wasm-bindgen macro frontend mentioned in the issue. Done means one #[pyo3] dispatcher covers the requested item forms and parameters, with tests for the supported features.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100