summaryrefslogtreecommitdiff
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/enum.py3
-rw-r--r--Lib/test/test_enum.py16
2 files changed, 19 insertions, 0 deletions
diff --git a/Lib/enum.py b/Lib/enum.py
index 8d23933d3e..1e028a364f 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -714,6 +714,9 @@ class Flag(Enum):
'|'.join([str(m._name_ or m._value_) for m in members]),
)
+ def __bool__(self):
+ return bool(self._value_)
+
def __or__(self, other):
if not isinstance(other, self.__class__):
return NotImplemented
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index cfe1b18e9a..cf704edb1b 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -1767,6 +1767,14 @@ class TestFlag(unittest.TestCase):
self.assertIs(Open.WO & ~Open.WO, Open.RO)
self.assertIs((Open.WO|Open.CE) & ~Open.WO, Open.CE)
+ def test_bool(self):
+ Perm = self.Perm
+ for f in Perm:
+ self.assertTrue(f)
+ Open = self.Open
+ for f in Open:
+ self.assertEqual(bool(f.value), bool(f))
+
def test_programatic_function_string(self):
Perm = Flag('Perm', 'R W X')
lst = list(Perm)
@@ -2137,6 +2145,14 @@ class TestIntFlag(unittest.TestCase):
self.assertFalse(W in RX)
self.assertFalse(X in RW)
+ def test_bool(self):
+ Perm = self.Perm
+ for f in Perm:
+ self.assertTrue(f)
+ Open = self.Open
+ for f in Open:
+ self.assertEqual(bool(f.value), bool(f))
+
class TestUnique(unittest.TestCase):
def test_unique_clean(self):