Would there be support for a more general cmp/__cmp__

Steven Bethard steven.bethard at gmail.com
Wed Oct 26 12:05:31 EDT 2005


Antoon Pardon wrote:
> Christopher Subich schreef :
> 
>> Antoon Pardon wrote:
>>> >>>from decimal import Decimal
>>> >>>Zero = Decimal(0)
>>> >>>cmp( ( ) , Zero)
>>> -1
>>> >>>cmp(Zero, 1)
>>> -1
>>> >>>cmp(1, ( ) )
>>> -1
>>
>> I'd argue that the wart here is that cmp doesn't throw an exception, not 
>> that it returns inconsistent results.  This is a classic case of 
>> incomparable objects, and saying that 1 < an empty tuple is bordering on 
>> meaningless.
> 
> I wont argue with you here, but it is what python gives as now.
> Changing this behaviour is not going to happen.

FWIW, Guido has said a few times that in Python 3.0 we should "Raise an 
exception when making comparisons (other than equality and inequality) 
between two incongruent types."[1]  But yes, the behavior won't change 
in the Python 2.X series due to backwards compatibility concerns.

STeVe

[1] http://wiki.python.org/moin/Python3%2e0



More information about the Python-list mailing list