tristate: implement __nonzero__() method
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Mon, 2 Jun 2014 07:14:52 +0000 (10:14 +0300)
committerGuido Günther <agx@sigxcpu.org>
Fri, 20 Feb 2015 20:17:17 +0000 (21:17 +0100)
Returns False if tristate is 'off', otherwise True ('on' or 'auto').

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
gbp/tristate.py

index 93610605e388b2dcf3c40e7e2f887a803206accd..0a800ecda2f4f53a8b2d5f6332fc73e30aeeed00 100644 (file)
@@ -66,6 +66,17 @@ class Tristate(object):
         else:
             return 'off'
 
+    def __nonzero__(self):
+        """
+        >>> Tristate('on').__nonzero__()
+        True
+        >>> Tristate('auto').__nonzero__()
+        True
+        >>> Tristate('off').__nonzero__()
+        False
+        """
+        return self._state is not self.OFF
+
     @property
     def state(self):
         """Get current state"""