Skip Montanaro <skip@mojam.com> writes: > I'm a bit confused about Guido's rich comparison stuff. In the description > he states that __le__ and __ge__ are inverses as are __lt__ and __gt__. > >From a boolean standpoint this just can't be so. Guido mentions partial > orderings, but I'm still confused. Consider this example: Objects of type A > implement rich comparisons. Objects of type B don't. If my code looks like > > a = A() > b = B() > ... > if b < a: > ... > > My interpretation of the rich comparison stuff is that either > > 1. Since b doesn't implement rich comparisons, the interpreter falls > back to old fashioned comparisons which may or may not allow the > comparison of B objects and A objects. > > or > > 2. The sense of the inequality is switched (a > b) and the rich > comparison code in A's implementation is called. > > That's my reading of it. It has to be wrong. The inverse comparison should > be a >= b, not a > b, but the described pairing of comparison functions > would imply otherwise. > > I'm sure I'm missing something obvious or revealing some fundamental failure > of my grade school education. Please explain... For a total order: a < b if and only if b > a. This is what the rich comparison code does. a < b if and only if a >= b. This is that the rich comparison code doesn't do. Does this make sense? Cheers, M. -- Presumably pronging in the wrong place zogs it. -- Aldabra Stoddart, ucam.chat
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4