[Python-ideas] Implement comparison operators for range objects

Alexander Belopolsky alexander.belopolsky at gmail.com
Fri Oct 14 21:52:18 CEST 2011


On Fri, Oct 14, 2011 at 1:23 PM, Guido van Rossum <guido at python.org> wrote:
..
> - add read-only attributes .start, .step, .stop
> - add slicing such that it normalizes .stop to .start + the right
> multiple of .step
> - add __eq__ and __hash__ which compare by .start, .step, .stop

-1

I did not see a clear statement of a use-case for any of these
features.  I could imagine convenience of __eq__ for those used to
range() returning a list, but comparing by .start, .step, .stop would
destroy this convenience.  If you need an object with .start, .step,
.stop, we already have the slice object.  NumPy has some functionality
to create a regular sequence from a slice object.  I don't see why
someone would need a __hash__.  If you want to key some values by
ranges, just use 3-tuples instead.



More information about the Python-ideas mailing list