Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Doc/library/enum.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ helper, :class:`auto`.

.. class:: auto

Instances are replaced with an appropriate value for Enum members. By default, the initial value starts at 1.
Instances are replaced with an appropriate value for Enum members.
:class:`StrEnum` defaults to the lower-cased version of the member name,
while other Enums default to 1 and increase from there.

.. versionadded:: 3.6 ``Flag``, ``IntFlag``, ``auto``

.. versionadded:: 3.10 ``StrEnum``

Creating an Enum
----------------
Expand Down
6 changes: 6 additions & 0 deletions Lib/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,12 @@ def __new__(cls, *values):

__str__ = str.__str__

def _generate_next_value_(name, start, count, last_values):
"""
Return the lower-cased version of the member name.
"""
return name.lower()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just name? Why .lower()?



def _reduce_ex_by_name(self, proto):
return self.name
Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -2179,6 +2179,12 @@ class Private(Enum):
self.assertEqual(Private._Private__corporal, 'Radar')
self.assertEqual(Private._Private__major_, 'Hoolihan')

def test_strenum_auto(self):
class Strings(StrEnum):
ONE = auto()
TWO = auto()
self.assertEqual([Strings.ONE, Strings.TWO], ['one', 'two'])


class TestOrder(unittest.TestCase):

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
StrEnum: fix _generate_next_value_ to return a str