This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author pboddie
Recipients pboddie
Date 2010-02-16.17:36:39
SpamBayes Score 6.29764e-07
Marked as misclassified No
Message-id <1266341801.65.0.120911514825.issue7942@psf.upfronthosting.co.za>
In-reply-to
Content
As noted here:

http://www.selenic.com/pipermail/mercurial/2010-February/030068.html

This is probably documented somewhere, and there may even be a good reason for the difference, but old-style classes raise TypeError when __len__ returns a non-int, whereas new-style classes raise OverflowError. The latter is probably just as valid, but the message is a bit obscure for debugging purposes.

Maybe this went away after 2.5 - if so, sorry for the noise!

Here's an illustration of the problem:

Python 2.5.4 (r254:67916, Nov  4 2009, 17:59:46)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class C:
...     def __len__(self):
...             return 2**35
...
>>> c = C()
>>> len(c)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __len__() should return an int
>>> class C(object):
...     def __len__(self):
...             return 2**35
...
>>> c = C()
>>> len(c)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: long int too large to convert to int
History
Date User Action Args
2010-02-16 17:36:41pboddiesetrecipients: + pboddie
2010-02-16 17:36:41pboddiesetmessageid: <1266341801.65.0.120911514825.issue7942@psf.upfronthosting.co.za>
2010-02-16 17:36:40pboddielinkissue7942 messages
2010-02-16 17:36:39pboddiecreate