[docs] [issue12067] Doc: remove errors about mixed-type comparisons.

Terry J. Reedy report at bugs.python.org
Sat Sep 22 23:01:57 CEST 2012

Terry J. Reedy added the comment:

You are right, I did not look deep enough. I was fooled by the conversion of NotImplemented, returned from object.__le__, etc, to TypeError. Sorry for that noise.

For comparison and arithmetic, the actual alternative to defining a function that returns NotImplemented seems to be to not define it at all.

class C():
    def __ge__(self, other):
        return True
    def __add__(self, other):
        return 44
    __radd__ = __add__

class O():
    pass  # removed NotImplemented defs
c = C()
o = O()
print(c >= o, o <= c)
# True True
print(c + o, o + c)
# 44 44

(I looked at the codes for binary_op1 in abstract.c and do_richcompare in object.c and do not yet see any effective difference between not defined and a NotImplemented return.)

I'll take a look at the patch later.


Python tracker <report at bugs.python.org>

More information about the docs mailing list