hbutils.model.compare

Overview:

Base interface to quickly implement a comparable object.

IComparable

class hbutils.model.compare.IComparable[source]
Overview:

Interface for a comparable object.

Examples::
>>> from hbutils.model import IComparable
>>> class MyValue(IComparable):
...     def __init__(self, v) -> None:
...         self._v = v
...
...     def _cmpkey(self):
...         return self._v
...
>>> MyValue(1) == MyValue(1)
True
>>> MyValue(1) == MyValue(2)
False
>>> MyValue(1) != MyValue(2)
True
>>> MyValue(1) > MyValue(2)
False
>>> MyValue(1) >= MyValue(2)
False
>>> MyValue(1) < MyValue(2)
True
>>> MyValue(1) <= MyValue(2)
True
__eq__(other)[source]

Return self==value.

__ge__(other)[source]

Return self>=value.

__gt__(other)[source]

Return self>value.

__le__(other)[source]

Return self<=value.

__lt__(other)[source]

Return self<value.

__ne__(other)[source]

Return self!=value.

_cmpkey()[source]

Function for getting a key value which is used for comparison.

Returns:

A value used to compare.