[Python-3000] ABC for Inequalities

Raymond Hettinger python at rcn.com
Tue Feb 12 01:43:54 CET 2008


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

One of the motivating examples in the ABC pep was that the presence of __getitem__ was insufficient to distinguish between a sequence and a mapping.  By registering one of the collections ABCs, a class can make an affirmative declaration that it is either a mapping or a sequence.

It seems that there is a similar issue with inequalities.  If something defines __le__, you don't necessarily know whether it returns a boolean (it could return an array of bools for a vector comparison).  Even if a bool is returned, it is not clear whether it implies sortable ordering or whether is something with a completely different meaning (i.e. set.issubset).


Raymond


More information about the Python-3000 mailing list