-
Notifications
You must be signed in to change notification settings - Fork 763
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 ordering magic methods for #[pyclass]
#3203
Conversation
c3b7a2c
to
a477688
Compare
As the new behavior may break users who were attempting to use |
I think this should happen only when that boiler plate reduction is in place. |
Completely agree. This PR is intended to be an addition only. I'd propose to then work on the opt-in implementation of |
(Pushed the wording adjustment as a new commit, when we're happy with what's going on here I'll squash.) |
Thanks, squashed! bors r=adamreichold |
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>
Build failed: |
bors retry |
Build succeeded! The publicly hosted instance of bors-ng is deprecated and will go away soon. If you want to self-host your own instance, instructions are here. If you want to switch to GitHub's built-in merge queue, visit their help page. |
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.