In Basic customisation, the python docs state about comparison methods:
[no swapped-argument versions of these methods]; rather,
__lt__()
and__gt__()
are each other’s reflection,__le__()
and__ge__()
are each other’s reflection, and__eq__()
and__ne__()
are their own reflection.
I'd be less surprised by __lt__()
and __ge__()
being each other’s reflection(, as well as __le__()
and __gt__()
).
While the docs also state:
… no other implied relationships among the comparison operators, for example, the truth of
(x<y or x==y)
does not implyx<=y
,
what, if anything, is the or would be a rationale for the reflection relations chosen?
Because a < b
and b > a
are equivalent, as are a <= b
and b >= a
.
Reflection means swapping the operands, not applying "not" to the operator.
__lt__(a,b)
# if we don't know what to do, call
return __gt__(b,a)
You were thinking the following
__lt__(a,b)
# if we don't know what to do
return not __ge__(a,b)
But that's not what reflection means.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With