-
-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
Implement comparison operators for range objects #57410
Comments
It seems some sort of consensus on how to compare range objects has emerged from the python-ideas discussion on comparison of range objects 1. The attached patch defines '==' and '!=' for range object equality based on the sequence of values they represent. The other comparison operators are left NotImplemented. |
Nice patch! I put some comments on Rietveld. |
Mark, thanks for your comments. Here's a new version of the patch, I answer on Rietveld. |
The new patch looks fine; I'd still like to have the more explicit reference counting in range_hash (see replies on Rietveld). A few more things:
|
Mark, thanks again for your comments. (I never looked at the Python source code before, so tey are highly appreciated.) I uploaded a new version of the patch hopefully. |
I get a test failure in test_hash (which is checking exactly that the hash(range) uses the default object hash, so that test is clearly out of date now). Apart from that, the latest patch looks good to me. I'm going to give this a couple of days in case anyone else has any comments, then I'll aim to commit it (with the extra test_hash fix) this weekend. Thanks for all the work on this! |
+ one = PyLong_FromLong(1); If would be nice to have a PyLong_CompareLong() function. |
I've taken the liberty of updating the patch, with a few minor changes: range_equality -> range_equals (like range_contains) Sven, Ezio: okay to apply this? |
Hmm. Why does my patch not get a 'review' button? |
Ah, there it is. Never mind. :-) |
Thanks for the updates, Mark. I was just about to look into this again. The changes are fine with me. |
Victor Stinner wrote:
In most cases, global variables Py_Zero and Py_One would be enough to simplify this kind of code. |
New changeset 479a7dd1ea6a by Mark Dickinson in branch 'default': |
Agreed. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: