[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:

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>

More information about the New-bugs-announce mailing list