Message170936
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() |
|
Date |
User |
Action |
Args |
2012-09-22 00:05:24 | terry.reedy | set | recipients:
+ terry.reedy, rhettinger, mark.dickinson, ezio.melotti, cvrebert, docs@python, mikehoy |
2012-09-22 00:05:23 | terry.reedy | set | messageid: <1348272323.83.0.295622691418.issue12067@psf.upfronthosting.co.za> |
2012-09-22 00:05:23 | terry.reedy | link | issue12067 messages |
2012-09-22 00:05:21 | terry.reedy | create | |
|