Re: [Python-Dev] Range __contains__ and objects with __index__ methods

2010-12-27 Thread Mark Dickinson
Bah. I meant to send this to the list. (I suspect that Nick also meant to send his reply to the list.) On Mon, Dec 27, 2010 at 12:43 PM, Mark Dickinson wrote: > On Mon, Dec 27, 2010 at 12:23 PM, Nick Coghlan wrote: >> The symmetry only breaks for a class that breaks the invariant: >> >>   x ==

Re: [Python-Dev] Range __contains__ and objects with __index__ methods

2010-12-26 Thread Nick Coghlan
On Mon, Dec 27, 2010 at 11:52 AM, Terry Reedy wrote: > Return a converted to an integer. Equivalent to a.__index__()." > comes close to implying equality (if possible). > > What are the actual used of .__index__? PEP 357 gives the original rationale - it was to allow integer-like objects (such as

Re: [Python-Dev] Range __contains__ and objects with __index__ methods

2010-12-26 Thread Martin v. Löwis
> What are the actual used of .__index__? Can you please rephrase this question? Regards, Martin ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/py

Re: [Python-Dev] Range __contains__ and objects with __index__ methods

2010-12-26 Thread Terry Reedy
On 12/26/2010 7:15 PM, Nick Coghlan wrote: Starting in Python 3.2, range() supports fast containment checking for integers (i.e. based on an O(1) arithmetic calculation rather than an O(N) iteration through the entire sequence). Currently, this fast path ignores objects that implement __index__

[Python-Dev] Range __contains__ and objects with __index__ methods

2010-12-26 Thread Nick Coghlan
Starting in Python 3.2, range() supports fast containment checking for integers (i.e. based on an O(1) arithmetic calculation rather than an O(N) iteration through the entire sequence). Currently, this fast path ignores objects that implement __index__ - they are relegated to the slow iterative se