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

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

| >>> print NotImplemented < None

As is this.  There is no reason to expect the two comparisons 
(NotImplemented to 0 and None) to give the same or different results.

| Does somebody know why is a difference here?

Different interpreters, different arbitrary results.  I believe checking 
the ids of the right objects (the type objects, I have read) would explain.

| 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 still NotImplemented < 0 versus NotImplemented < None.  As I 
understand, such nonsense comparisions will raise exceptions in 3.0.

tjr



_______________________________________________
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

Reply via email to