Message7241

Author Arfrever
Recipients Arfrever
Date 2012-06-18.18:57:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1340045871.17.0.169001656975.issue1929@psf.upfronthosting.co.za>
In-reply-to
Content
__len__ of new-style classes should raise OverflowError instead of TypeError for compatibility with CPython.

$ jython2.7
Jython 2.7.0a2+ (default:2cc31de620ba+, cze 17 2012, 09:04:11) 
[OpenJDK 64-Bit Server VM (Oracle Corporation)] on java1.7.0_03-icedtea
Type "help", "copyright", "credits" or "license" for more information.
>>> class X(object):
...     def __len__(self):
...         return 2 ** 70
... 
>>> len(X())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __len__ should return a int
>>>
$ python2.7
Python 2.7.3+ (2.7:0add70dd3c43+, Jun 17 2012, 04:30:39) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class X(object):
...     def __len__(self):
...         return 2 ** 70
... 
>>> len(X())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: long int too large to convert to int
>>>
$ python3.2
Python 3.2.3+ (3.2:714b8f91f3d4+, Jun 17 2012, 04:59:08) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class X:
...     def __len__(self):
...         return 2 ** 70
... 
>>> len(X())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: cannot fit 'int' into an index-sized integer
>>>
History
Date User Action Args
2012-06-18 18:57:51Arfreversetrecipients: + Arfrever
2012-06-18 18:57:51Arfreversetmessageid: <1340045871.17.0.169001656975.issue1929@psf.upfronthosting.co.za>
2012-06-18 18:57:51Arfreverlinkissue1929 messages
2012-06-18 18:57:49Arfrevercreate