On Wed, Oct 12, 2011 at 1:33 PM, Sven Marnach <sven@marnach.net> wrote:
Comparing the representations doesn't ever seem useful, though.  The
only way to access the original start, stop and step values is by
parsing the representation, and these values don't affect the
behaviour of the range object in any other way.  Moreover, they might
even change implicitly:

   >>> range(5, 10, 3)
   range(5, 10, 3)
   >>> range(5, 10, 3)[:]
   range(5, 11, 3)

I can't imagine any situation which I would like to consider the above
two ranges different in.


def test_copy_range(self):
    """Make sure that every time we call copy_range we get a new identical copy of the range."""
    a = range(5, 10, 3)
    b = copy_range(a)
    c = copy_range(a)
    self.assert(a is not b)
    self.assert(a is not c)
    self.assert(b is not c)
    self.assert(repr(a) == repr(b))
    self.assert(repr(a) == repr(c))

Anyway, my thought is that if you think this change should be made it would be helpful to have a use case other than unit tests as for those purposes, explicit list() or repr() is more clear and performance is not typically an issue. Why would you normally be comparing ranges at all?

--- Bruce