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

Daniel Stutzbach daniel at stutzbachenterprises.com
Tue Sep 2 23:18:08 CEST 2008


On Tue, Sep 2, 2008 at 3: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.


len() is useful for more than iteration, such as setting the bounds for a
binary search (e.g., over a large on-disk data structure)

 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

--
Daniel Stutzbach, Ph.D.
President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-3000/attachments/20080902/7ee455e8/attachment.htm>


More information about the Python-3000 mailing list