[Python-Dev] NotImplemented comparisons

Guido van Rossum guido at python.org
Thu Aug 2 20:35:44 CEST 2007


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.)

--Guido

On 8/2/07, Facundo Batista <facundobatista at gmail.com> wrote:
> People:
>
> Pablo Hoffman opened this bug: "[1764761] Decimal comparison with None
> fails in Windows".
>
> It's not a Decimal problem, see the differente behaviour of this basic
> test in Linux and Windows:
>
> Python 2.5.1 (r251:54863, May  2 2007, 16:56:35) [GCC 4.1.2 (Ubuntu
> 4.1.2-0ubuntu4)] on linux2
> >>> class C(object):
> ...     def __cmp__(self, other):
> ...         return NotImplemented
> ...
> >>> c = C()
> >>> print c < None
> False
> >>> print NotImplemented < None
> False
>
>
> Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
> (Intel)] on win32
> >>> class C(object):
>     def __cmp__(self, other):
>         return NotImplemented
>
> >>> c = C()
> >>> print c < None
> True
> >>> print NotImplemented < None
> False
>
>
> Here's where I stop: don't know where to keep looking... Does somebody
> know why is a difference here?
>
> Furthermore, we can check that is a problem regarding __cmp__:
>
> >>> class C(object):
>     def __cmp__(self, other):
>         return NotImplemented
>     def m(self):
>         return NotImplemented
>
> >>> c = C()
> >>> print c < None
> True
> >>> print c.m() < None
> False
>
>
> This is not the first time I find an issue through Decimal regarding
> NotImplemented, there was this thread:
>
>     http://mail.python.org/pipermail/python-dev/2005-December/059046.html
>
> , but I don't know if that's a separate issue or not.
>
> Thanks for your help!
>
> --
> .    Facundo
>
> Blog: http://www.taniquetil.com.ar/plog/
> PyAr: http://www.python.org/ar/
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/guido%40python.org
>


-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list