From 9fa2dab904a0242c11e5f12069b923b1281b2264 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Mon, 2 Jun 2014 10:14:52 +0300 Subject: [PATCH] tristate: implement __nonzero__() method Returns False if tristate is 'off', otherwise True ('on' or 'auto'). Change-Id: I6ade27fc85c6d05ed69dc694495b70725070d9c5 Signed-off-by: Markus Lehtonen --- gbp/tristate.py | 11 +++++++++++ 1 file changed, 11 insertions(+) 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""" -- 2.7.4