from datetime import timedelta
class A:
def __abs__(self):
return -self
class B1(A):
def __neg__(self):
return 'neg from B1'
class B2(timedelta):
def __neg__(self):
return 'neg from B2'
print(abs(B1())) # neg from B1
print(abs(B2(-1))) # 1 day, 0:00:00
Why does the first print call use the overridden method, but the second one doesn't? I don't understand. The second case appears to also call -self
in the python implementation here.