https://github.com/python/cpython/commit/5f9e38f9b9f2b82e841f1b11a8300f2cacd76a36
commit: 5f9e38f9b9f2b82e841f1b11a8300f2cacd76a36
branch: main
author: Nacho Caballero <[email protected]>
committer: ethanfurman <[email protected]>
date: 2025-07-21T08:18:40-07:00
summary:

gh-136859: Improve `StrEnum` docs (GH-136864)

Co-authored-by: Nacho Caballero <[email protected]>
Co-authored-by: Antonio Spadaro <[email protected]>

files:
M Doc/library/enum.rst

diff --git a/Doc/library/enum.rst b/Doc/library/enum.rst
index c9b2c7d76b6746..2cfc2f4962979f 100644
--- a/Doc/library/enum.rst
+++ b/Doc/library/enum.rst
@@ -504,16 +504,31 @@ Data Types
 
 .. class:: StrEnum
 
-   ``StrEnum`` is the same as :class:`Enum`, but its members are also strings 
and can be used
-   in most of the same places that a string can be used.  The result of any 
string
-   operation performed on or with a *StrEnum* member is not part of the 
enumeration.
+   *StrEnum* is the same as :class:`Enum`, but its members are also strings and
+   can be used in most of the same places that a string can be used. The result
+   of any string operation performed on or with a *StrEnum* member is not part
+   of the enumeration.
+
+   >>> from enum import StrEnum, auto
+   >>> class Color(StrEnum):
+   ...     RED = 'r'
+   ...     GREEN = 'g'
+   ...     BLUE = 'b'
+   ...     UNKNOWN = auto()
+   ...
+   >>> Color.RED
+   <Color.RED: 'r'>
+   >>> Color.UNKNOWN
+   <Color.UNKNOWN: 'unknown'>
+   >>> str(Color.UNKNOWN)
+   'unknown'
 
    .. note::
 
       There are places in the stdlib that check for an exact :class:`str`
       instead of a :class:`str` subclass (i.e. ``type(unknown) == str``
       instead of ``isinstance(unknown, str)``), and in those locations you
-      will need to use ``str(StrEnum.member)``.
+      will need to use ``str(MyStrEnum.MY_MEMBER)``.
 
    .. note::
 

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to