summaryrefslogtreecommitdiffstats
path: root/Doc/library/enum.rst
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2016-01-15 23:01:33 (GMT)
committerEthan Furman <ethan@stoneleaf.us>2016-01-15 23:01:33 (GMT)
commit60255b67b986d4c448153bef16755599afbfdaa2 (patch)
tree40835fb60bb87fcbbab7418e5230eeaa64d47f46 /Doc/library/enum.rst
parent43cfd8240c274b2f4cf0588f3defae83e7379a55 (diff)
downloadcpython-60255b67b986d4c448153bef16755599afbfdaa2.zip
cpython-60255b67b986d4c448153bef16755599afbfdaa2.tar.gz
cpython-60255b67b986d4c448153bef16755599afbfdaa2.tar.bz2
revert change 87a9dff5106c: pure Enum members again evaluate to True;
update Finer Points section of docs to cover boolean evaluation; add more tests for pure and mixed boolean evaluation
Diffstat (limited to 'Doc/library/enum.rst')
-rw-r--r--Doc/library/enum.rst11
1 files changed, 10 insertions, 1 deletions
diff --git a/Doc/library/enum.rst b/Doc/library/enum.rst
index a76f5a3..377ac3e 100644
--- a/Doc/library/enum.rst
+++ b/Doc/library/enum.rst
@@ -257,7 +257,7 @@ members are not integers (but see `IntEnum`_ below)::
>>> Color.red < Color.blue
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
- TypeError: '<' not supported between instances of 'Color' and 'Color'
+ TypeError: unorderable types: Color() < Color()
Equality comparisons are defined though::
@@ -747,6 +747,15 @@ besides the :class:`Enum` member you looking for::
.. versionchanged:: 3.5
+Boolean evaluation: Enum classes that are mixed with non-Enum types (such as
+:class:`int`, :class:`str`, etc.) are evaluated according to the mixed-in
+type's rules; otherwise, all members evaluate as ``True``. To make your own
+Enum's boolean evaluation depend on the member's value add the following to
+your class::
+
+ def __bool__(self):
+ return bool(self._value_)
+
The :attr:`__members__` attribute is only available on the class.
If you give your :class:`Enum` subclass extra methods, like the `Planet`_