Python 3 __cmp__ semantic change?

Colin J. Williams cjw at ncf.ca
Sat Nov 22 11:17:59 EST 2008


Johannes Bauer wrote:
> Steve Holden schrieb:
> 
>> If it's not present then it would be worth reporting it as a 3.0 bug -
>> there's still time to get it in, as the release isn't due until early
>> December.
> 
> Seems it was removed on purpose - I'm sure there was a good reason for
> that, but may I ask why? Instead of the sleek __cmp__ function I had
> earlier, I now have code like:
> 
> 
> def __lt__(self, other):
> 	return self.__cmp__(other) < 0
> 	
> def __le__(self, other):
> 	return self.__cmp__(other) < 0
> 	
> def __gt__(self, other):
> 	return self.__cmp__(other) > 0
> 
> def __ge__(self, other):
> 	return self.__cmp__(other) >= 0
> 
> Does anyone know the reason why __cmp__ was discarded?
> 
> Kind regards,
> Johannes
> 

Johannes,

Isn't the problem with your original 
post that x and y are either of 
different types or, is of the same type 
that the values of that type are not 
strictly comparable?  It seems that the 
old approach was to make a recursive 
comparison.

Colin W.



More information about the Python-list mailing list