bt2: make `BoolValue` inherit `_IntegralValue`
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 28 Jun 2019 04:02:01 +0000 (00:02 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 3 Jul 2019 01:31:27 +0000 (21:31 -0400)
This is just like

    issubclass(bool, numbers.Integral)
    issubclass(bool, int)

are true.

It makes `BoolValue` behave even more like `bool`, for example you can
now do:

    3 << bt2.BoolValue(True)

(which is 6).

Also remove BoolValue.__eq__() because _NumericValue.__eq__() does the
job now.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Icbcd8d41b9f064c77586e0b7bfdf4a772c15f0f7
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1565
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
src/bindings/python/bt2/bt2/value.py

index 7f003c2bba69bf8f7d6678da3b04114168e1b211..9cdad357c3a2605cb962711a8a4153381ec834b5 100644 (file)
@@ -285,7 +285,7 @@ class _RealValue(_NumericValue, numbers.Real):
     pass
 
 
-class BoolValue(_Value):
+class BoolValue(_IntegralValue):
     _NAME = 'Boolean'
 
     def __init__(self, value=None):
@@ -297,12 +297,6 @@ class BoolValue(_Value):
         self._check_create_status(ptr)
         super().__init__(ptr)
 
-    def __eq__(self, other):
-        try:
-            return self._value == self._value_to_bool(other)
-        except:
-            return False
-
     def __bool__(self):
         return self._value
 
This page took 0.025254 seconds and 4 git commands to generate.