summaryrefslogtreecommitdiffstats
path: root/Doc/library/enum.rst
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2020-09-22 20:00:07 (GMT)
committerGitHub <noreply@github.com>2020-09-22 20:00:07 (GMT)
commitd986d1657e1e7b50807d0633cb31d96a2d866d42 (patch)
tree2565f560e2ccacd2655c9e1fcbeff429c27750de /Doc/library/enum.rst
parent947adcaa13080790167757664912c3a6c2d4c201 (diff)
downloadcpython-d986d1657e1e7b50807d0633cb31d96a2d866d42.zip
cpython-d986d1657e1e7b50807d0633cb31d96a2d866d42.tar.gz
cpython-d986d1657e1e7b50807d0633cb31d96a2d866d42.tar.bz2
bpo-41816: `StrEnum.__str__` is `str.__str__` (GH-22362)
use `str.__str__` for `StrEnum` so that `str(StrEnum.member)` is the same as directly accessing the string value of the `StrEnum` member
Diffstat (limited to 'Doc/library/enum.rst')
-rw-r--r--Doc/library/enum.rst15
1 files changed, 15 insertions, 0 deletions
diff --git a/Doc/library/enum.rst b/Doc/library/enum.rst
index 3e9b1f9..118002b 100644
--- a/Doc/library/enum.rst
+++ b/Doc/library/enum.rst
@@ -622,6 +622,11 @@ an incorrect member::
Before :class:`StrEnum`, ``Directions.NORTH`` would have been the :class:`tuple`
``('north',)``.
+.. note::
+
+ Unlike other Enum's, ``str(StrEnum.member)`` will return the value of the
+ member instead of the usual ``"EnumClass.member"``.
+
.. versionadded:: 3.10
@@ -1243,3 +1248,13 @@ all named flags and all named combinations of flags that are in the value::
>>> Color(7) # not named combination
<Color.CYAN|MAGENTA|BLUE|YELLOW|GREEN|RED: 7>
+``StrEnum`` and :meth:`str.__str__`
+"""""""""""""""""""""""""""""""""""
+
+An important difference between :class:`StrEnum` and other Enums is the
+:meth:`__str__` method; because :class:`StrEnum` members are strings, some
+parts of Python will read the string data directly, while others will call
+:meth:`str()`. To make those two operations have the same result,
+:meth:`StrEnum.__str__` will be the same as :meth:`str.__str__` so that
+``str(StrEnum.member) == StrEnum.member`` is true.
+