[Python-3000] Should len() clip to sys.maxsize or raiseOverflowError?

Adam Olsen rhamph at gmail.com
Tue Sep 2 23:34:26 CEST 2008


On Tue, Sep 2, 2008 at 2:53 PM, Guido van Rossum <guido at python.org> wrote:
> The only time when __len__ can be larger than sys.maxsize is when the
> class implements some kind of virtual space where the values are
> computed on the fly. In such cases trying to walk over all values is
> bound to take forever, and the length is likely not of all that much
> interest to the caller -- but sometimes we may need to pass such an
> object to some library code we didn't write that is making some
> trivial use of len(), like the examples I gave before.
>
> That said, I would actually be okay with the status quo (which does
> raise an OverflowError) as long as we commit to fixing this properly
> in 2.7 / 3.1, by removing the range restriction (like we've done for
> other int operations a long time ago).

+1

Otherwise it sounds like these virtual containers shouldn't support
len() at all.  Maybe a .len() method instead, with all the TMTOWTDI
that implies.


-- 
Adam Olsen, aka Rhamphoryncus


More information about the Python-3000 mailing list