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

Support exporting Rust enums to Python (old school / without data) #834

Closed
davidhewitt opened this issue Mar 25, 2020 · 8 comments · Fixed by #2034
Closed

Support exporting Rust enums to Python (old school / without data) #834

davidhewitt opened this issue Mar 25, 2020 · 8 comments · Fixed by #2034

Comments

@davidhewitt
Copy link
Member

Following suggestion this is a subset of #417 to focus just on exporting Rust enums without data to Python. These should be fairly straightforward to support - we could borrow inspiration from C++'s boost.Python and pybind11. We might also want compatibility with the Python enum library.

@davidhewitt davidhewitt changed the title Support exporting Rust enums without data to Python Support exporting Rust enums to Python (old school / without data) Mar 25, 2020
@programmerjake
Copy link
Contributor

I have some messy code that you can use as a reference (originally mentioned in #417): https://salsa.debian.org/Kazan-team/simple-soft-float/-/blob/e19291a0b8eb17e9b52c09b8e670bf0fe3244989/src/python_macros.rs

@kngwyu kngwyu modified the milestone: 0.9.0 Jun 21, 2020
@davidhewitt davidhewitt added this to the 0.12 milestone Jun 21, 2020
@davidhewitt
Copy link
Member Author

I'm nominating this for 0.12.

@gilescope
Copy link
Contributor

Jake's code looks like a good starting place. Has anyone had a go at it? Happy to test out PRs. I could have a crack at it myself but I think the PR would need a fair bit of hand holding...

@davidhewitt
Copy link
Member Author

davidhewitt commented Jul 17, 2020

I haven't had a go yet, but I plan to have a go soon unless someone else claims this issue sooner!

@stillinbeta
Copy link

I made an attempt (#1045), but I got frustrated by the amount of boilerplate and traits required.

@davidhewitt
Copy link
Member Author

As we've got a fair bit to release in 0.12 I'm going to move this to the 0.13 milestone

@davidhewitt davidhewitt modified the milestones: 0.12, 0.13 Sep 7, 2020
@davidhewitt davidhewitt modified the milestones: 0.13, 0.14 Dec 22, 2020
@davidhewitt davidhewitt modified the milestones: 0.14, 0.15 Apr 13, 2021
@Legend-of-iPhoenix
Copy link

Are there any recommended workarounds for the time being? I was considering just adding a python implementation, but I really don't want to have to maintain two copies of the same code in my project :)

@davidhewitt
Copy link
Member Author

You could construct a #[pyclass] with a bunch of #[classattr] to represent all the variants.

It's worth pointing out that #1045 is nearly there, just needs a willing person to rebase and finish it off.

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

Successfully merging a pull request may close this issue.

7 participants