[Python-ideas] Implement comparison operators for range objects
Nick Coghlan
ncoghlan at gmail.com
Thu Oct 13 03:43:53 CEST 2011
On Thu, Oct 13, 2011 at 11:06 AM, Guido van Rossum <guido at python.org> wrote:
> Yeah, we're down to bikeshedding about whether range(0, 10, 2) ==
> range(0, 11, 2).
I'll weigh in on the "compare like a sequence" side, even if the
specific range definitions are different. It's the way range
comparisons work in Python 2 and I'd like range() objects to be as
close to a computationally defined immutable list as we can get them.
It may even make sense to make them hashable in those terms.
I see it as similar to the fact that "Decimal('1') == Decimal('1.0')"
even though those two objects carry additional state regarding
significant digits that the definition of equivalence ignores.
But not exposing start/stop/step is a definite oversight - I actually
thought we *did* expose them, but I was thinking of slice objects.
With those attributes exposed, anyone that wants a more restrictive
form of equality can easily implement it for themselves.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas
mailing list