Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a #[pyo3] macro #211

Open
konstin opened this issue Aug 25, 2018 · 1 comment
Open

Add a #[pyo3] macro #211

konstin opened this issue Aug 25, 2018 · 1 comment

Comments

@konstin
Copy link
Member

konstin commented Aug 25, 2018

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.

@davidhewitt
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants