[Python-3000] ABC for Inequalities

Raymond Hettinger python at rcn.com
Tue Feb 12 02:45:01 CET 2008


>> Was some thought given to providing a mixin for boolean 
>> inequalities in total orderings (define __le__ and get 
>> the rest for free)

[GvR]
> 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.


Raymond


---------------------------
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).
    '''
    @abstractmethod
    def __eq__(self, other): pass

    @abstractmethod
    def __ne__(self, other): pass
    
    @abstractmethod
    def __lt__(self, other): pass

    @abstractmethod
    def __le__(self, other): pass

    @abstractmethod
    def __gt__(self, other): pass

    @abstractmethod
    def __ge__(self, other): pass


More information about the Python-3000 mailing list