[issue2723] Truncate __len__() at sys.maxsize

Alexander Belopolsky report at bugs.python.org
Wed Apr 30 15:42:19 CEST 2008


Alexander Belopolsky <belopolsky at users.sourceforge.net> added the comment:

On Wed, Apr 30, 2008 at 2:32 AM, Raymond Hettinger
<report at bugs.python.org> wrote:

>  Wouldn't it be better to raise OverflowError or somesuch?

Thats what the current code does.  I don't know what Guido's full
rationale is, but I guess the idea is that len(..) is not supposed to
raise an exception on sizeable objects.

Here is a quote from another message:

"""
__len__ will always be problematic when there are more values than can
be counted in a signed C long; maybe we should do what the Java
collections package does: for once, Java chooses practicality over
purity, and simply states that if the length doesn't fit, the largest
number that does fit is returned (i.e. for us that would be
sys.maxsize in 3.0, sys.maxint in 2.x).
"""
-- Guido van Rossum, 2008-04-30
http://mail.python.org/pipermail/python-3000/2008-April/013340.html

I suspect, however, that part of Java's motivation for this behavior
is that exceptions need to be declared and declaring the length method
as throwing OverflowError would make many programmers very unhappy.

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2723>
__________________________________


More information about the Python-bugs-list mailing list