Base class for sorting based self._sort_key
Source code in src/robot/utils/sortable.py
| class Sortable:
"""Base class for sorting based self._sort_key"""
_sort_key = NotImplemented
def __test(self, operator, other, require_sortable=True):
if isinstance(other, Sortable):
return operator(self._sort_key, other._sort_key)
if not require_sortable:
return False
raise TypeError("Cannot sort '%s' and '%s'."
% (type_name(self), type_name(other)))
def __eq__(self, other):
return self.__test(eq, other, require_sortable=False)
def __lt__(self, other):
return self.__test(lt, other)
def __le__(self, other):
return self.__test(le, other)
def __gt__(self, other):
return self.__test(gt, other)
def __ge__(self, other):
return self.__test(ge, other)
def __hash__(self):
return hash(self._sort_key)
|