Hm... IIRC the reason why we did this for `__r*__` is because the more derived class might want to return an instance of that class, and we can't assume that the less derived class knows how to create an instance of the more derived class (the `__init__` signatures might differ).
But the interesting bit is skipping the call of __r*__ when `lhs.__r*__ == rhs.__r*__` (as long as the derived class requirements are met). That's the difference that I'm really curious about compared to rich comparisons and their inverse which don't have this call avoidance.
Ooh, interesting. (Aren't you missing a few checks for MISSING in the elif or else branches?)
Let me guess some more (I'm on a rare caffeine high since 9am so we'll see how this goes :-).
The idea is clearly that if lhs and rhs are the same class we don't bother calling `__r*__` (because if `__*__` didn't do it there's no reason that `__r*__` would be any different).
Are you sure you read things right, and `__r*__` is skipped when the `__r*__` methods are the same, and not only when the lhs and rhs classes are the same?
It does seem kind of a pointless optimization, since if the first call is successful we'll skip the second call anyway, and if it returns NotImplemented, well, if our assumption that `__r*__` is going to do the same, it's going to be an error anyway. I wonder if this was always there? Maybe we should study the git blame some more.
And why don't we do this for rich comparisons? Probably because the logic is completely separate. :-( And maybe when we did rich comparisons (nearly a decade after the original binary operator overloading IIRC) the optimization idea didn't occur to us, or maybe we realized that we'd be optimizing an error case. Or maybe because rich comparisons were trying to somehow model the earlier `__cmp__`?
[SNIP]
I think we could try to change it but it would require a very careful risk analysis.
I'm not sure how critical it is to change. I'm sure there's some potential perf gain by avoiding the (potentially) unnecessary call, but I also don't know if people have implemented these functions in such a way that skipping the inverse operation on the right-hand side object would break something. Would abuse of the syntax make a difference (e.g. making `>` do something magical)?
I don't know, PEP 207 explicitly says the reflexivity assumptions are assumed. I guess I misunderstood your question for clarification as a suggestion to change.
I feel this requires more careful thought than I can muster tonight.