bpo-41816: `StrEnum.__str__` is `str.__str__` (GH-22362) · python/cpython@d986d16 · GitHub
Skip to content

Commit d986d16

Browse files
authored
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
1 parent 947adca commit d986d16

3 files changed

Lines changed: 48 additions & 0 deletions

File tree

Doc/library/enum.rst

Lines changed: 15 additions & 0 deletions

Lib/enum.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,8 @@ def __new__(cls, *values):
718718
member._value_ = value
719719
return member
720720

721+
__str__ = str.__str__
722+
721723

722724
def _reduce_ex_by_name(self, proto):
723725
return self.name

Lib/test/test_enum.py

Lines changed: 31 additions & 0 deletions

0 commit comments

Comments
 (0)