First the code:
class myClass(object):
def __cmp__(self, other):
return cmp(type(self), type(other)) or cmp(self.__something, other.__something)
Does this produce the same ordering as for other types in python? Is there a correct idiom for this?
A bit of looking around on google I found some pertinent information in the python docs. Quoting:
Implementation note: Objects of different types except numbers are ordered by their type names; objects of the same types that don’t support proper comparison are ordered by their address.
This suggests that If I want to follow that behavior, I should use
class myClass(object):
def __cmp__(self, other):
return (cmp(self.__class__.__name__, other.__class__.__name) or
cmp(self.__something, other.__something))
Especially unfortunate is that I may have an extraordinarily difficult time mantaining transitivity with dict
s, which is a special case I had hoped to implement.
Do I even need to check the types of my arguments? does python even let me see this?