msg145705 - (view) |
Author: Sven Marnach (smarnach) |
Date: 2011-10-17 14:52 |
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. [1]: http://mail.python.org/pipermail/python-ideas/2011-October/012376.html |
|
|
msg145714 - (view) |
Author: Mark Dickinson (mark.dickinson) *  |
Date: 2011-10-17 15:28 |
Nice patch! I put some comments on Rietveld. |
|
|
msg145727 - (view) |
Author: Sven Marnach (smarnach) |
Date: 2011-10-17 16:55 |
Mark, thanks for your comments. Here's a new version of the patch, I answer on Rietveld. |
|
|
msg145746 - (view) |
Author: Mark Dickinson (mark.dickinson) *  |
Date: 2011-10-17 18:23 |
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: - The patch needs a Misc/NEWS entry before committing; it probably deserves a line in Doc/whatsnew/3.3.rst, too. - The doc update should have a ".. versionchanged:: 3.3" note. - Maybe the range_compare function could be renamed to something that makes it clearer it's just doing an equality comparison rather than a generalized comparison. 'range_equality_check'? Or just 'range_equal' or 'range_equality'? |
|
|
msg145796 - (view) |
Author: Sven Marnach (smarnach) |
Date: 2011-10-18 11:31 |
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. |
|
|
msg146015 - (view) |
Author: Mark Dickinson (mark.dickinson) *  |
Date: 2011-10-20 13:19 |
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! |
|
|
msg146016 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2011-10-20 13:23 |
+ one = PyLong_FromLong(1); + if (!one) + return -1; + cmp_result = PyObject_RichCompareBool(r0->length, one, Py_EQ); + Py_DECREF(one); If would be nice to have a PyLong_CompareLong() function. |
|
|
msg146172 - (view) |
Author: Mark Dickinson (mark.dickinson) *  |
Date: 2011-10-22 15:38 |
I've taken the liberty of updating the patch, with a few minor changes: range_equality -> range_equals (like range_contains) move identity check into range_equals move comments before the code they describe (PEP7) add whatsnew entry remove check that range.__hash__ matches object.__hash__ in test_hash change assertEqual into assertIs where appropriate (as suggested by Ezio) additional comments and tests in Lib/test/test_range (ditto) Sven, Ezio: okay to apply this? |
|
|
msg146173 - (view) |
Author: Mark Dickinson (mark.dickinson) *  |
Date: 2011-10-22 15:40 |
Hmm. Why does my patch not get a 'review' button? |
|
|
msg146174 - (view) |
Author: Mark Dickinson (mark.dickinson) *  |
Date: 2011-10-22 15:40 |
Ah, there it is. Never mind. :-) |
|
|
msg146198 - (view) |
Author: Sven Marnach (smarnach) |
Date: 2011-10-22 22:51 |
Thanks for the updates, Mark. I was just about to look into this again. The changes are fine with me. |
|
|
msg146199 - (view) |
Author: Sven Marnach (smarnach) |
Date: 2011-10-22 22:54 |
Victor Stinner wrote: > If would be nice to have a PyLong_CompareLong() function. In most cases, global variables Py_Zero and Py_One would be enough to simplify this kind of code. |
|
|
msg146244 - (view) |
Author: Roundup Robot (python-dev)  |
Date: 2011-10-23 18:53 |
New changeset 479a7dd1ea6a by Mark Dickinson in branch 'default': Issue #13201: equality for range objects is now based on equality of the underlying sequences. Thanks Sven Marnach for the patch. http://hg.python.org/cpython/rev/479a7dd1ea6a |
|
|
msg146245 - (view) |
Author: Mark Dickinson (mark.dickinson) *  |
Date: 2011-10-23 18:53 |
> In most cases, global variables Py_Zero and Py_One would be enough to > simplify this kind of code. Agreed. |
|
|