diff options
| author | Peter LaFosse <peter@vector35.com> | 2021-09-23 10:08:31 -0400 |
|---|---|---|
| committer | Peter LaFosse <peter@vector35.com> | 2021-09-23 10:25:41 -0400 |
| commit | b4ddd2c1f18c88d225fbcf984661d85002211549 (patch) | |
| tree | fa569e92608ecd4087680f85b1015e4907b0366d /python/types.py | |
| parent | 49ec2348ca236595d2d0154a163c547c6a8b83d3 (diff) | |
Add equality and order overloads for BoolWithConfidence
Diffstat (limited to 'python/types.py')
| -rw-r--r-- | python/types.py | 21 |
1 files changed, 21 insertions, 0 deletions
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 |
