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.

Title: __len__ can't return big numbers
Type: enhancement Stage:
Components: Interpreter Core Versions: Python 3.5
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: akira, cool-RR, jcea, mark.dickinson, r.david.murray, rhettinger
Priority: low Keywords:

Created on 2014-05-05 23:11 by cool-RR, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 17934 merged Zac Hatfield-Dodds, 2020-01-10 12:13
Messages (7)
msg217957 - (view) Author: Ram Rachum (cool-RR) * Date: 2014-05-05 23:11
I want to use big numbers for length.

>>> class A:
...     __len__ = lambda self: 10 ** 20
>>> len(A())
Traceback (most recent call last):
  File "<pyshell#5>", line 1, in <module>
OverflowError: cannot fit 'int' into an index-sized integer
msg217958 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-05-06 00:47
While this is classed as a CPython implementation detail (see issue 15718) it doesn't sound like it is likely to be changed (see issue 2723).
msg217974 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2014-05-06 09:58
Whoops; sorry -- accidental title change by typing `__len__` into something that wasn't the search box.

Stupid fingers...

(I suspect this issue is a duplicate of an existing issue.)
msg217983 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-05-06 13:46
Mark: I thought it was too, but the two I noted were the closest I could find.  Maybe you'll find something even more on point :)
msg217988 - (view) Author: Akira Li (akira) * Date: 2014-05-06 14:59
If `len()` signature can't be changed to return Python int objects (unlimited) then the OverflowError may contain the actual `.length`
 property instead (based on msg66459 by Antoine Pitrou)


    def length(sized):
        """Return the true (possibly large) length of `sized` object.

        It is equivalent to len(sized) if len doesn't raise 
        OverflowError i.e., if the length is less than sys.maxsize on
        CPython; otherwise return OverflowError.length attribute
            return len(sized)
        except OverflowError as e:
            return e.length
msg218002 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2014-05-06 18:44
That's pretty evil. :-)
msg218124 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2014-05-08 21:00
I recommend this be closed:  too much impact on existing code for too little benefit.  

CPython has historically imposed some artificial implementation specific details in order make the implementation cleaner and faster internally (i.e. a limit on the number of function arguments, sys.maxsize limits, etc.)
Date User Action Args
2022-04-11 14:58:03adminsetgithub: 65643
2020-01-10 12:13:55Zac Hatfield-Doddssetpull_requests: + pull_request17341
2014-05-08 21:17:54benjamin.petersonsetstatus: open -> closed
resolution: wont fix
2014-05-08 21:00:46rhettingersetpriority: normal -> low
versions: + Python 3.5, - Python 3.4
nosy: + rhettinger

messages: + msg218124

type: enhancement
2014-05-06 18:44:53mark.dickinsonsetmessages: + msg218002
2014-05-06 14:59:41akirasetnosy: + akira
messages: + msg217988
2014-05-06 13:46:34r.david.murraysetmessages: + msg217983
2014-05-06 09:58:58mark.dickinsonsetnosy: + mark.dickinson
messages: + msg217974
2014-05-06 09:57:56mark.dickinsonsettitle: __len__ -> __len__ can't return big numbers
2014-05-06 09:57:40mark.dickinsonsettitle: __len__ can't return big numbers -> __len__
2014-05-06 09:53:11jceasetnosy: + jcea
2014-05-06 00:47:34r.david.murraysetnosy: + r.david.murray
messages: + msg217958
2014-05-05 23:11:11cool-RRcreate