[Python-3000] ABC for Inequalities
Guido van Rossum
guido at python.org
Tue Feb 12 04:08:58 CET 2008
Hold on. We went down that road quite a bit and then discovered it
wasn't going to work. The problem is that if you have two instance x,
y such that isinstance(x, TotalOrdering) and isinstance(y,
TotalOrdering) you still don't know if x < y is defined. (For example,
if x is a string and y is a number.) We ended up deciding that such an
ABC was not useful. There's a useful definition in there somewhere but
it's elusive. We'll eventually figure it out.
On Feb 11, 2008 5:45 PM, Raymond Hettinger <python at rcn.com> wrote:
> >> Was some thought given to providing a mixin for boolean
> >> inequalities in total orderings (define __le__ and get
> >> the rest for free)
> > IOW it's messy.
> Would it make sense to do something in numbers.py modeled
> after Exact/InExact? Those don't have any behavior; they
> just make a statement about semantics.
> class TotalOrdering(object):
> '''Equality and inequality operations on this type are guaranteed to
> return boolean values and to imply a total ordering where the relations
> are transitive (a<b and b<c implies a<c) and the operators have the
> usual interrelationships: (a<b) == (b>a) == (not a>=b) == (not b<=a).
> def __eq__(self, other): pass
> def __ne__(self, other): pass
> def __lt__(self, other): pass
> def __le__(self, other): pass
> def __gt__(self, other): pass
> def __ge__(self, other): pass
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-3000