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
This commit is contained in:
Ethan Furman 2020-09-22 13:00:07 -07:00 committed by GitHub
parent 947adcaa13
commit d986d1657e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 0 deletions

View file

@ -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.