PyO3 / PyO3/pyo3

Add a `#[pyo3]` macro

Open
#211 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

1.0-candidate needs-design
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 $struct and impl $protocol for $struct. The macro can decide where it's attached to by using syn::parseinto a syn::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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.