[Python-checkins] cpython (3.4): Issue26748: Enum classes should evaluate as True
ethan.furman
python-checkins at python.org
Thu Apr 14 03:04:12 EDT 2016
https://hg.python.org/cpython/rev/772805538caf
changeset: 100962:772805538caf
branch: 3.4
parent: 100644:ed85850499bd
user: Ethan Furman <ethan at stoneleaf.us>
date: Wed Apr 13 23:52:09 2016 -0700
summary:
Issue26748: Enum classes should evaluate as True
files:
Lib/enum.py | 6 ++++++
Lib/test/test_enum.py | 13 +++++++++++++
2 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/Lib/enum.py b/Lib/enum.py
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -193,6 +193,12 @@
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.
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -257,6 +257,19 @@
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):
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list