-
Notifications
You must be signed in to change notification settings - Fork 803
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Support __eq__
for pyclass
#2089
Comments
At the moment you should implement Let's leave this issue open, because I think with the new |
Thanks for explaining! |
To me, it feels like the most ergonomic thing would be to offer something like |
@ssokolow there's been suggestions previously to have Just not got around to implementing! |
I don't necessarily want dataclass support... just the ability to proxy implementations through easily. (My most recent example would have been fine with (Even then, since I was also porting from rust-cpython to PyO3 at the same time and this is my first use of PyO3, I wound up turning |
Ah, interesting. I will have a think about whether there's a nice way to do this - it might solve some papercuts I've had too! |
Being able to define |
Finally pushed #3203 to implement this! |
3203: support ordering magic methods for `#[pyclass]` r=adamreichold a=davidhewitt Closes #2089 This adds `__lt__`, `__le__`, `__eq__`, `__ne__`, `__gt__`, and `__ge__` as per the Python implementations of what we call `__richcmp__`. There's a UI test confirming that the user cannot implement split forms and `__richcmp__` simultaneously. There's also a benchmark comparing implementing these split methods against using `__richcmp__`. I couldn't see a meaningful performance difference, so I'm tempted to deprecate `__richcmp__`, given that's not a magic method which exists in Python. Potentially we can provide options such as the opt-in `#[pyclass(eq, ord)]` to avoid boilerplate for people who don't want to implement six different methods. Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
I don't think is possible to create a class like this in pyo3. I couldn't find a way to write an equality method in the docs.
I need to be able to write an implementation for this so I can make a python wrapper around rust enums. I found that there wasn't a way to do an equality check. I'm considered writing an
is_equal_to
method then making another class in python that knows how to useis_equal_to
when you call__eq__
. I want to avoid this because I think its clunky and requires a lot of boilerplate. Forcing an end user to use a method likeis_equal_to
is jarring so I can't do that.The text was updated successfully, but these errors were encountered: