[Python-3000] PEPs 3106 and 3119

Guido van Rossum guido at python.org
Thu Aug 21 18:18:26 CEST 2008


2008/8/21 Nick Coghlan <ncoghlan at gmail.com>:
> Levi wrote:
>> Now, I understand that set doesn't return NotImplemented to avoid having
>> it's __cmp__ method called, but what I don't get is why it has a __cmp__
>> method at all. I thought the entire point of set and co. using the rich
>> comparison operators is that Sets only define a partial ordering and so
>> shouldn't define __cmp__, which implies a total ordering. So why define
>> a __cmp__ method that only raises an error at the expense of breaking
>> the rich comparison operators?
>
> set() and frozenset() do this to prevent falling back to the default
> ordering employed in Python 2.x:
>
>>>> obj1 = type('T1', (), {})
>>>> obj2 = type('T2', (), {})
>>>> obj1 < obj2
> True
>>>> obj1 > obj2
> False
>
> It should be possible to make them play more nicely with others in 3.x
> where that undesirable fallback behaviour is gone though.

I thought in 3.0 they already behave cooperatively? set_richcompare()
returns NotImplemented (where in 2.x it raises TypeError.)

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list