gchar.utils.compare¶
Comparable¶
-
class
gchar.utils.compare.
Comparable
[source]¶ Base class that allows subclasses to perform arbitrary comparison operations by implementing the necessary interfaces.
Subclasses need to implement the _key method, which returns the key used for comparison.
Supported comparison operators: ==, !=, >=, >, <=, <
- Usage:
Subclass Comparable and implement the _key method.
Objects of the subclass can then be compared using the defined comparison operators.
- Example:
>>> class MyComparable(Comparable): >>> def __init__(self, value): >>> self.value = value ... >>> def _key(self): >>> return self.value ... >>> obj1 = MyComparable(5) >>> obj2 = MyComparable(10) >>> print(obj1 == obj2) # False >>> print(obj1 < obj2) # True
-
__eq__
(other)[source]¶ Implementation of the equality operator (==).
- Parameters:
other (object) – The other object to compare.
- Returns:
True if the objects are equal, False otherwise.
- Return type:
bool
-
__ge__
(other)[source]¶ Implementation of the greater than or equal to operator (>=).
- Parameters:
other (object) – The other object to compare.
- Returns:
True if the current object is greater than or equal to the other object, False otherwise.
- Return type:
bool
-
__gt__
(other)[source]¶ Implementation of the greater than operator (>).
- Parameters:
other (object) – The other object to compare.
- Returns:
True if the current object is greater than the other object, False otherwise.
- Return type:
bool
-
__le__
(other)[source]¶ Implementation of the less than or equal to operator (<=).
- Parameters:
other (object) – The other object to compare.
- Returns:
True if the current object is less than or equal to the other object, False otherwise.
- Return type:
bool
-
__lt__
(other)[source]¶ Implementation of the less than operator (<).
- Parameters:
other (object) – The other object to compare.
- Returns:
True if the current object is less than the other object, False otherwise.
- Return type:
bool
-
__ne__
(other)[source]¶ Implementation of the inequality operator (!=).
- Parameters:
other (object) – The other object to compare.
- Returns:
True if the objects are not equal, False otherwise.
- Return type:
bool
-
_check_same_type
(other)[source]¶ Helper method to check if the type of the other object is the same as the current object’s type.
- Parameters:
other (object) – The other object to compare.
- Returns:
The other object if the types are the same.
- Return type:
object
- Raises:
TypeError – If the types are different.