Re: [Python-Dev] NotImplemented comparisons
2007/8/2, Guido van Rossum <guido@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? Thanks! -- . Facundo Blog: http://www.taniquetil.com.ar/plog/ PyAr: http://www.python.org/ar/
On 02/08/07, Facundo Batista <facundobatista@gmail.com> wrote:
I understand that is tricky how NotImplemented and comparisons interact.
But how do you explain the difference in behaviour between Linux and Windows?
A wild guess: c < None falls back to checking c.__cmp__(None) < 0. This translates to NotImplemented < 0, and as the ordering of built in types is implementation dependent, maybe that explains the difference between Windows and Linux? Paul.
Facundo Batista schrieb:
2007/8/2, Guido van Rossum <guido@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.
participants (3)
-
Facundo Batista
-
Georg Brandl
-
Paul Moore