__cmp__ deprecation (was Re: Python 3.0, rich comparisons and sorting order)

Aahz aahz at pythoncraft.com
Tue Sep 21 20:46:55 EDT 2004


In article <mailman.3683.1095800082.5135.python-list at python.org>,
Carlos Ribeiro  <carribeiro at gmail.com> wrote:
>
>Given all the arguments, I'm changing my approach to the sorting
>problem. My proposal is that sortable objects should provide a __key__
>method. sort() already accepts a key function to be passed. As of
>today, there are 4 different ways to customize sorting behavior:
>
>1) passing a comparison function to sort();
>2) passing a key generation function to sort();
>3) implementing __cmp__;
>4) implementing rich comparison methods. 
>
>If the current sorting behavior is to be changed -- as proposed for
>Py3K --, I think that relying on methods such as (3) and (4) is not a
>good idea; __cmp__ is already on the way to deprecation, and rich
>comparisons are already being extended for other uses that have
>nothing to do with sorting. 

AFAIK, there are no plans to officially deprecate __cmp__; there are too
many use cases for needing a three-way comparison, and when it's
expensive to compare objects, you want to do it only once.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"A foolish consistency is the hobgoblin of little minds, adored by little
statesmen and philosophers and divines."  --Ralph Waldo Emerson



More information about the Python-list mailing list