Commit 268c20ef authored by Ethan Furman's avatar Ethan Furman

Issue26748: Enum classes should evaluate as True

parent 3c69bee1
......@@ -193,6 +193,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):
"""Either returns an existing member, or creates a new enum class.
......
......@@ -257,6 +257,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):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment