-
Notifications
You must be signed in to change notification settings - Fork 760
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
pymethods: add support for protocol methods #1864
Conversation
7827e51
to
75c0116
Compare
This is now pretty close to mergeable. Most the numerical methods are now supported. There's a few TODOs I've left at the bottom of
I definitely really like how this feels for pyclass usage - I can just start defining TBH, given that this doesn't actually break Something like:
|
Ok, this is now as complete as I want it to be to merge a first version. All the traits above are covered. The TODOs above still apply, additionally there's a couple more:
I think we've discussed this concept enough already in #1206, so any reviews here would be about reading the code. If anyone has time to do so: comments, questions, and nits are all welcome. It would be nice to make sure what I've built is maintainable. I'll merge this next weekend if there's no objections by then; I think this is a great step forward, but there's a lot of follow-up TODOs which we can track once this goes in and gets the ball rolling. I'm sure there's a lot of cleanup and refactoring that could yet still be done in |
988da49
to
179b5d1
Compare
I can't really give a technical review of this, because that's a lot of code I'm not familiar with, but I'd just like to say thank you for doing this 👍 I wonder, can we do Anyway I plan to try this out and write some things about it in the next few weeks. |
😄 thanks - I do this for pleasure though it's always nice to enjoy a shout-out!
Yes I actually was intending to propose to change
I'll add both to the TODOs further up. |
Ok I'm going to proceed to merge this now! If anyone else has outstanding comments, please bring them to the discussion in #1884 |
This is the beginning of an implementation which makes it possible to implement
__dunder__
methods directly in#[pymethods]
instead of requiring separate protocols.From experimentation here it looks like it should be possible to support this alongside the existing
#[pyproto]
traits. This would allow us to deprecate#[pyproto]
in 0.15 rather than flat-out remove, giving users a little bit of time to migrate.Similarly, that enables the implementation for this to come in chunks.
There's a number of things this first PR won't cover:
__dunder__
at the Python level, so we'll need to design one__sequence_getitem__
methods etc to be explicit.multiple-pymethods
featureAll of the above can be recorded in a tracking issue once this first PR is merged.
This first PR is not ready yet. Progress as follows:
Overall, having solved
PyObjectProtocol
andPyDescrProtocol
I've satisfied myself that I have an approach that can work. There's a lot of janky codegen added topyo3-macros-backend/src/pymethod.rs
. This can definitely be refactored further and made better.I use dtolnay specialization to merge the
__setattr__
and__delattr__
methods into the single slot they share. The same technique should work to handle the "reversible" methods inPyNumberProtocol
.For reviewing - at the moment this code is rather hacky, so might be hard to follow. That said, anyone who's curious is welcome to review and comment at any time! I'll come back to make progress on this whenever I get a chance...