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.

classification
Title: OverflowError in len(range(2**63))
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.9, Python 3.8, Python 3.7, Python 3.6
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: Nosy List: Zac Hatfield-Dodds, mark.dickinson
Priority: normal Keywords:

Created on 2020-01-06 02:18 by Zac Hatfield-Dodds, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg359394 - (view) Author: Zac Hatfield-Dodds (Zac Hatfield-Dodds) * Date: 2020-01-06 02:18
The value for `len` internally passes through an `ssize_t`, which means that it raises OverflowError for (very) large collections.

This is admittedly only possible with collections such as `range` that do not store all their elements in memory, but it would still be nice to have `len(range(n)) == n` without caveats.

This was found via a teaching example and is now tracked in my repo of property-based tests for CPython:
https://github.com/rsokl/Learning_Python/pull/125
https://github.com/Zac-HD/stdlib-property-tests/blob/bb46996ca4500381ba09a8cd430caaddd71910bc/tests.py#L28-L34

Related to https://bugs.python.org/issue26423, but it's still present in the development branches for 3.7, 3.8, and 3.9; and instead of a wrong result it's an error (which is better!).
msg359405 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2020-01-06 07:39
Duplicate of #12159?
msg359406 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2020-01-06 07:45
(See also #21444)
History
Date User Action Args
2022-04-11 14:59:25adminsetgithub: 83408
2020-01-07 01:33:00rhettingersetstatus: open -> closed
resolution: duplicate
stage: resolved
2020-01-06 07:45:02mark.dickinsonsetmessages: + msg359406
2020-01-06 07:39:32mark.dickinsonsetnosy: + mark.dickinson
messages: + msg359405
2020-01-06 02:18:32Zac Hatfield-Doddscreate