advanced programming techniques supplied (in factpython automatically produces if is supplied!if =is suppliedand >if <is suppliedso it is sufficient to just implement the three operators <<=and =and to leave python to infer the others howeverusing the class decorator reduces the minimum that we must implement to just this is convenientand also ensures that all the comparison operators use the same consistent logic def complete_comparisons(cls)assert cls __lt__ is not object __lt__"{ must define and ideally ==format(cls __name__)if cls __eq__ is object __eq__cls __eq__ lambda selfother(not (cls __lt__(selfotheror cls __lt__(otherself))cls __ne__ lambda selfothernot cls __eq__(selfothercls __gt__ lambda selfothercls __lt__(otherselfcls __le__ lambda selfothernot cls __lt__(otherselfcls __ge__ lambda selfothernot cls __lt__(selfotherreturn cls one problem that the decorator faces is that class object from which every other class is ultimately derived defines all six comparison operatorsall of which raise typeerror exception if used so we need to know whether and =have been reimplemented (and are therefore usablethis can easily be done by comparing the relevant special methods in the class being decorated with those in object if the decorated class does not have custom the assertion fails because that is the decorator' minimum requirement and if there is custom =we use itotherwisewe create one then all the other methods are created and the decorated classnow with all six comparison methodsis returned using class decorators is probably the simplest and most direct way of changing classes another approach is to use metaclassesa topic we will cover later in this abstract base classes |an abstract base class (abcis class that cannot be used to create objects insteadthe purpose of such classes is to define interfacesthat isto in effect list the methods and properties that classes that inherit the abstract base class must provide this is useful because we can use an abstract base class as kind of promise-- promise that any derived class will provide the methods and properties that the abstract base class specifies python' abstract base classes are described in pep (www python org/dev/peps/pep- )which also includes very useful rationale and is well worth reading metaclasses