Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: Add 'ord' option for PyClass and corresponding tests #4202
feat: Add 'ord' option for PyClass and corresponding tests #4202
Changes from 5 commits
0cd69e4
676e1a5
21abf24
cea1677
01e76bd
c6349c6
ea90363
d02f65b
8d2a974
3fbd4b0
be00a8f
5ed0cf5
708c934
38ab0d1
455893d
c924dab
8c11647
6788067
736a4b8
ff81849
1259901
14b5760
b2851c7
f8c782d
102b074
574266d
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Nit: the rest of these were alphabetical, it might be nice to move this branch up to the right place in the ordering.
This same observation applies to a few similar additions above and below.
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.
Done! Also, I have updated the documentation with this feature.
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.
A thought: should we require a
PartialOrd
implementation forpyclass(ord)
? I see two upsides:__pyo3__int__
.PartialOrd
implementation anyway as__pyo3__int__
wouldn't be possible, so again this seems good for consistency.If we agree, as far as implementation would go, just remove the calls to convert with
__pyo3__int__
from these branches.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.
That was also one of my first thoughts, but then we should probably also require
PartialEq
for the already existing impls.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.
Requiring PartialOrd seems reasonable to me. Would requiring PartialEq break anything for current implementations? If we require PartialOrd, would the ensure_spanned checks still be required?
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.
I think requiring
PartialEq
would break compiles, but it'd also be trivial to fix for these simple enum cases (just add the derive). @Icxolu would you be ok if we agree that we should requirePartialEq
but postpone changing that to a future PR / tracking issue where we can also add#[pyclass(eq)]
at the same time?I also would love to have
#[pyclass(hash)]
to be implemented (again, requiringHash
).... and then a future step is working out how to apply all of these to structs to get dataclass-like functionality :)
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.
If you mean the checks for
ord
not being accepted on structs, we'll still need those (unless we extend this PR to makeord
work for every type of#[pyclass]
, which I think should be possible with a bit more 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.
I'm good with that, sounds like a nice followup to this one 👍
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.
Yes, I think making
ord
work for all of these types would be great in this PR. I will scope this out and raise any questions along the way.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.
Nice tests 👍