summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>2014-06-02 10:14:52 +0300
committerGuido Günther <agx@sigxcpu.org>2015-02-20 21:17:17 +0100
commitf0890215c84ecf5bf4f87e3c17563f0b13fd739e (patch)
tree3dd22c6376595b41755a753e92fa9487ce7b2022
parent60ad28f4fb016463b25c18cb37dd6b2bebb613bb (diff)
tristate: implement __nonzero__() method
Returns False if tristate is 'off', otherwise True ('on' or 'auto'). Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
-rw-r--r--gbp/tristate.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/gbp/tristate.py b/gbp/tristate.py
index 9361060..0a800ec 100644
--- a/gbp/tristate.py
+++ b/gbp/tristate.py
@@ -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"""