summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/enum.py6
-rw-r--r--Lib/test/test_enum.py13
2 files changed, 19 insertions, 0 deletions
diff --git a/Lib/enum.py b/Lib/enum.py
index ac89d6b..476e3b3 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -212,6 +212,12 @@ class EnumMeta(type):
enum_class.__new__ = Enum.__new__
return enum_class
+ def __bool__(self):
+ """
+ classes/types should always be True.
+ """
+ return True
+
def __call__(cls, value, names=None, *, module=None, qualname=None, type=None, start=1):
"""Either returns an existing member, or creates a new enum class.
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index 7985948..e5e0ec0 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -254,6 +254,19 @@ class TestEnum(unittest.TestCase):
with self.assertRaises(AttributeError):
del Season.SPRING.name
+ def test_bool_of_class(self):
+ class Empty(Enum):
+ pass
+ self.assertTrue(bool(Empty))
+
+ def test_bool_of_member(self):
+ class Count(Enum):
+ zero = 0
+ one = 1
+ two = 2
+ for member in Count:
+ self.assertTrue(bool(member))
+
def test_invalid_names(self):
with self.assertRaises(ValueError):
class Wrong(Enum):