[Python-3000] PEPs 3106 and 3119

Nick Coghlan ncoghlan at gmail.com
Thu Aug 21 12:19:46 CEST 2008


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.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
            http://www.boredomandlaziness.org


More information about the Python-3000 mailing list