From b4ddd2c1f18c88d225fbcf984661d85002211549 Mon Sep 17 00:00:00 2001 From: Peter LaFosse Date: Thu, 23 Sep 2021 10:08:31 -0400 Subject: Add equality and order overloads for BoolWithConfidence --- python/types.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'python') diff --git a/python/types.py b/python/types.py index 67ad8438..2a141846 100644 --- a/python/types.py +++ b/python/types.py @@ -369,6 +369,27 @@ class BoolWithConfidence: value:bool confidence:int=core.max_confidence + def __eq__(self, other): + if not isinstance(other, self.__class__): + return self.value == bool(other) + else: + return (self.value, self.confidence) == (other.value, other.confidence) + + def __ne__(self, other): + return not (self == other) + + def __gt__(self, other): + return self.confidence > other.confidence + + def __le__(self, other): + return self.confidence <= other.confidence + + def __ge__(self, other): + return self.confidence >= other.confidence + + def __lt__(self, other): + return self.confidence < other.confidence + def __bool__(self): return self.value -- cgit v1.3.1