[New-bugs-announce] [issue39227] OverflowError in len(range(2**63))
Zac Hatfield-Dodds
report at bugs.python.org
Sun Jan 5 21:18:32 EST 2020
New submission from Zac Hatfield-Dodds <zac.hatfield.dodds at gmail.com>:
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!).
----------
components: Interpreter Core
messages: 359394
nosy: Zac Hatfield-Dodds
priority: normal
severity: normal
status: open
title: OverflowError in len(range(2**63))
type: behavior
versions: Python 3.6, Python 3.7, Python 3.8, Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39227>
_______________________________________
More information about the New-bugs-announce
mailing list