[Python-Dev] NotImplemented comparisons

Georg Brandl g.brandl at gmx.net
Thu Aug 2 22:15:46 CEST 2007


Facundo Batista schrieb:
> 2007/8/2, Guido van Rossum <guido at python.org>:
> 
>> NonImplemented isn't treated as special when returned by __cmp__();
>> __cmp__ is not considered a binary operator like __add__. (__lt__ and
>> friends *do* get treated as such -- but instead of __rlt__ we use
>> __gt__, etc.)
> 
> I understand that is tricky how NotImplemented and comparisons interact.
> 
> But how do you explain the difference in behaviour between Linux and Windows?

I now investigated that, and it seems that if you return NotImplemented from
a __cmp__() function, and the other's __cmp__() isn't helpful either, you end
up comparing the addresses of the objects (in your case c and None) -- the
outcome of which is not consistent across machines or sessions.


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.



More information about the Python-Dev mailing list