-
Notifications
You must be signed in to change notification settings - Fork 782
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
feat: support pyclass on tuple enums #4072
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for following on this. Don't worry about being busy, happens to all of us, sometimes there are more important things.
This is already looking very good to me. I left a few comments to simplify the code a bit. Regarding using Cow
in FnArg
, that was not my suggestion, but I agree with that. While leaking would probably be fine, I think using Cow
would be the cleaner solution. If you would like open a separate PR for that, that would be fine with me.
Also just giving @carderne a ping, such that we don't duplicate work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much 🙏 . I think we're getting really close now 🚀.
The slot and __match_args__
handling looks great.
I marked a few spots, where we can reduce some code and some (optional) style nits.
There are two pieces that I would like to address before merge.
For the documentation in the guide I think we should encourage using indexing and tuple match for these tuple variants. This should be a pretty minor change just adapting the examples.
The second point is to also support constructor customization here, which we just landed for struct variants in #4158. This should also be a pretty simple change and I added a note in the corresponding place.
(I hope I'm not putting too much additional work on your table 🙃 )
a85b94b
to
160ad27
Compare
Am I missing anything else or is this ready for final review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me now. clippy-beta
is failing right now, but once that's fixed I think this is good to go 🚀 . Thanks again for putting in the effort and pushing this over the line!
As |
Nice work @newcomertv, I'm learning a bit going through where I went wrong trying to figure this out. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me too, with just a few suggestions...
Thanks for the review. I‘m quite busy right now. I‘ll try to take a look and fix those tomorrow or the day after. |
- take py from function argument on get_item - make more general slot def implementation - remove unnecessary function arguments - add testcases for uncovered cases including future feature match_args
I hope this fixes the remaining issues. :-) ( gh-pages appears to have failed due to lychee being unable to reach |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me too, thanks again!
#3748
Based on @mkovaxx 's https://github.com/PyO3/pyo3/pull/3582/files
Adds support for #[pyclass] for enums containing Tuple Variants.
Supports:
This introduces an issue that I didn't know how to solve quickly: Since the fields have no identifiers I need to create them inside the derive macro. Since they need to outlive their context where they are created as
FnArg
requires a&'a Ident
I ended up creating a Box::leak based identifier.I'm not sure how bad this is in the first place since it is only during the build process (code gen) and extremely small.
Addressing the getitem issue the comments on #4135 were very helpful.
Thanks to @carderne for fixing the doc issues, trying to solve the getitem problem and seeing the value in this PR :) - I had a few busy weeks and didn't get to continue working on this PR until now.
I hope I didn't miss any further documentation requirements or am missing any testcases.
Blocking issues:
If we need this before this PR gets merged I can open a seperate PR. (Though I'm not keen on it). A tracking issue has been opened within Replace &'a Ident with Cow in FnArg Enum #4156
__match_args__
needs to be generated as we already support matching through the subclass generation.