This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: need StrEnum in
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.10
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ethan.furman Nosy List: barry, eli.bendersky, ethan.furman, serhiy.storchaka, terry.reedy
Priority: normal Keywords: patch

Created on 2020-09-19 19:20 by ethan.furman, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 22337 merged ethan.furman, 2020-09-21 13:04
PR 22362 merged ethan.furman, 2020-09-22 14:46
Messages (5)
msg377186 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2020-09-19 19:20
Due to the nature of `str`, if an Enum tries to mixin the str type, all of it's members will be strings -- even if they didn't start out that way:

  class MyStrEnum(str, Enum):
     tuple = 'oops',
     okay = 'correct'

  >>> list(MyStrEnum)
  [<MyStrEnum.tuple: "('oops',)">, MyStrEnum.okay: 'correct'>]

The StrEnum class will have a check to ensure that each value was already a string, or can be converted to a string via

  str(bytes, encoding, errors)
msg377294 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2020-09-22 00:23
New changeset 0063ff4e583505e69473caa978e476ea4c559b83 by Ethan Furman in branch 'master':
bpo-41816: add `StrEnum` (GH-22337)
msg377321 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2020-09-22 14:01
From Serhiy Storchaka:
The only exception is StrEnum -- overriding __str__ of str
subclass may be not safe. Some code will call str() implicitly, other
will read the string content of the object directly, and they will be
msg377347 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2020-09-22 20:00
New changeset d986d1657e1e7b50807d0633cb31d96a2d866d42 by Ethan Furman in branch 'master':
bpo-41816: `StrEnum.__str__` is `str.__str__` (GH-22362)
msg377348 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2020-09-22 20:01
Thank you for your help, Serhiy!
Date User Action Args
2022-04-11 14:59:35adminsetgithub: 85982
2020-09-22 20:01:30ethan.furmansetstatus: open -> closed
resolution: fixed
messages: + msg377348

stage: patch review -> resolved
2020-09-22 20:00:25ethan.furmansetmessages: + msg377347
2020-09-22 14:46:33ethan.furmansetstage: needs patch -> patch review
pull_requests: + pull_request21400
2020-09-22 14:01:00ethan.furmansetstatus: closed -> open
resolution: fixed -> (no value)
messages: + msg377321

stage: resolved -> needs patch
2020-09-22 03:59:07ethan.furmansetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-09-22 00:23:25ethan.furmansetmessages: + msg377294
2020-09-21 13:04:59ethan.furmansetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request21382
2020-09-19 19:20:58ethan.furmancreate