Author terry.reedy
Recipients cvrebert, docs@python, ezio.melotti, mark.dickinson, mikehoy, rhettinger, terry.reedy
Date 2012-09-22.00:05:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1348272323.83.0.295622691418.issue12067@psf.upfronthosting.co.za>
In-reply-to
Content
After further thought: This section is about the syntax operators, not the special methods. The syntax operators never evaluate to NotImplemented as they (apparently) interpret its return from a special method the same as a raising of TypeError, and always raise TypeError when neither the op or its reflection is supported. So there should be no mention of NotImplemented here. Just a reference to 3.3. #15997 is related to my 'wonder' but not directly relevant to a patch for this. Please submit a draft patch when you have one.

I determined that 'raise TypeError' and 'return NotImplemented' both result in the call of the reflected method, at least for a couple of cases. (And same seems true for arithmetic ops too.)

class C():
    def __ge__(self, other):
        # print("in C.__ge__", end='')
        return True
    def __add__(self, other):
        return 44
    __radd__ = __add__

class O():
    def __le__(self, other):
        # print ("in O.__le__")
        return NotImplemented
    def __add__(self, other):
        return NotImplemented
    
c = C()
o = O()
ob = object() 
print(c >= o, o <= c, ob <= c)
# True True True
# print(ob <= ob) # raises TypeError
print(c + o, o + c, ob + c)
# 44 44 44
# print(ob + ob)  # raises TypeError
# print(ob >= o)  # with O.__le__ print uncommented
# in O.__le__  # so non-implemented reflected o <= ob *is* called
# TypeError: unorderable types: object() >= O()
History
Date User Action Args
2012-09-22 00:05:24terry.reedysetrecipients: + terry.reedy, rhettinger, mark.dickinson, ezio.melotti, cvrebert, docs@python, mikehoy
2012-09-22 00:05:23terry.reedysetmessageid: <1348272323.83.0.295622691418.issue12067@psf.upfronthosting.co.za>
2012-09-22 00:05:23terry.reedylinkissue12067 messages
2012-09-22 00:05:21terry.reedycreate