[Python-ideas] Implement comparison operators for range objects

Guido van Rossum guido at python.org
Thu Oct 13 02:19:31 CEST 2011


On Wed, Oct 12, 2011 at 3:57 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
> Guido van Rossum wrote:
>>
>> I beg to differ with all those who want range(0, 10, 2) == range(0,
>> 11, 2).
>
> I think practicality should beat purity here -- if the same results will be
> generated, then the ranges are the same and should be equal, no matter which
> exact parameters were used to create them.

Then we'd be forever stuck with not exporting the start/stop/step
values. I'd much rather export those (like the slice() object does).

(IOW I find the lack of exported start/stop/step values an omission,
not a feature, and would like to fix that too.)

>> After all the repr() shows the end point that was requested,
>> not the end point after "normalization" (or whatever you'd call it) so
>> the three parameters that went in should be considered state.
>>
>> OTOH range(10) == range(0, 10) == range(0, 10, 1).
>
> Exactly.

Because their repr() is the same: "range(0, 10)", thus proving that
the internal state is the same.

For range objects, I believe that the internal state represents what
theey really "mean", and the sequence of vallues generated by
iterating merely follows.

-- 
--Guido van Rossum (python.org/~guido)



More information about the Python-ideas mailing list