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

Leif Walsh leif.walsh at gmail.com
Sat Aug 30 23:17:22 CEST 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sat, Aug 30, 2008 at 11:07 AM, Hagen Fürstenau  wrote:
> While __len__() is allowed to return a value of any size, issues 2723
> and 3729 need a decision on what len() should do if the value doesn't
> fit in a Py_ssize_t.
>
> In a previous thread
> (http://mail.python.org/pipermail/python-3000/2008-May/013387.html)
> Guido wanted len() to "lie" and return sys.maxsize in this case, but
> several people have voiced strong discomfort with that. Any comments
> or pronouncements?

I didn't read the whole thread, but I did like the idea of using
returning sys.maxsize for __length_hint__, and not __length__.

That said, knowingly returning an incorrect value for __len__ sounds
awful.  I'd much prefer the OverflowError (which would let me catch it
and use sys.maxsize if I wanted, anyway), and would make the point
that many things in the Java world (for example, fallacious functions
being called 'practical') are good examples of Evil.

- --
Cheers,
Leif


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAki5uOIACgkQfBqXGvVwnEluKQCfWWC0R6kXH8z/GqmW5/hORLjK
mBAAni4OdgPhnlGxvBLtZmtt/L2d6SbA
=AEeb
-----END PGP SIGNATURE-----


More information about the Python-3000 mailing list