On Thu, Apr 24, 2008 at 11:50 AM, Nick Coghlan <[EMAIL PROTECTED]> wrote:
> There's definitely some bugs in this area of the range object code though: > > >>> x = range(2**33, 2) > >>> len(x) > 0 > >>> x[0] > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > IndexError: range object index out of range > Hmm. I'm not seeing the bug here. What am I missing? It seems to me that there are two reasonable behaviours for range(a, b) when b is less than a: return an 'empty' range, as in the example above, or raise a ValueError; I can see arguments for both behaviours. But one good argument in favour of the current behaviour is that xrange(a, b) in Python 2.x currently returns an empty range when b < a: >>> xrange(3, -2) xrange(3, 3) > I also believe that the OverflowError from doing len(self) while attempting > to index into the range should be intercepted and converted to something > more meaningful for the actual operation requested by the programmer (e.g. > "ValueError: Cannot index range objects with sys.maxsize or more elements") > Agreed. Though if it's easy to fix things so that range(a, b)[n] always 'just works' for any integer a <= n < b, and if the fix doesn't have any significant performance impact, wouldn't that be even better? Mark
_______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com