Terry Reedy schrieb: > "Facundo Batista" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > | >>> class C(object): > | ... def __cmp__(self, other): > | ... return NotImplemented > | ... > > Given that you 'should' return an int, doing elsewise has undefined > results.
Returning anything other than an int or NotImplemented raises an exception. NotImplemented seems to be special cased so that the other object's __cmp__ can be tried too. > | >>> c = C() > | >>> print c < None > > I presume that this translates into c.__compare(None) < 0 which becomes > NotImplemented < 0. The result of that is undefined and interpreter > dependent. No, it becomes id(c) < id(None). See half_compare in Objects/typeobject.c. > This is still NotImplemented < 0 versus NotImplemented < None. As I > understand, such nonsense comparisions will raise exceptions in 3.0. Yes, fortunately. Georg -- Thus spake the Lord: Thou shalt indent with four spaces. No more, no less. Four shall be the number of spaces thou shalt indent, and the number of thy indenting shall be four. Eight shalt thou not indent, nor either indent thou two, excepting that thou then proceed to four. Tabs are right out. _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com