mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
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:
parent
947adcaa13
commit
d986d1657e
3 changed files with 48 additions and 0 deletions
|
@ -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.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue