[Python-ideas] Implement comparison operators for range objects

Nick Coghlan ncoghlan at gmail.com
Sat Oct 15 09:52:17 CEST 2011


On Sat, Oct 15, 2011 at 12:07 PM, Terry Reedy <tjreedy at udel.edu> wrote:
> If range.stop were allowed to be None, as is slice.stop, we also would not
> need itertools.count, which is the third way we represent a virtual stepped
> subsequence of ints.

No, you don't want to do that - being finite is an important property
of range objects.

The thing about slice objects is that they're deliberately incomplete
- you need to supply a sequence length in order to "realise" them.
This is done via slice.indices(container_len)

Now, *there's* a powerful use case in favour of making 3.x range
behave just like a tuple of integers: we could update slice.indices()
to return one of those instead of wastefully creating the full tuple
of indices in memory the way it does now.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-ideas mailing list