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.

classification
Title: adjust enum.auto's behavior for StrEnum to return the enum name
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ethan.furman Nosy List: barry, eli.bendersky, ethan.furman
Priority: normal Keywords: patch

Created on 2020-11-17 09:01 by Antony.Lee, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 23727 closed ethan.furman, 2020-12-10 03:28
PR 23735 merged ethan.furman, 2020-12-10 18:56
Messages (5)
msg381220 - (view) Author: Antony Lee (Antony.Lee) * Date: 2020-11-17 09:01
Currently, enum.auto doesn't work with the new (Py3.10) StrEnum: `class E(enum.StrEnum): a = enum.auto()` results in `TypeError: 1 is not a string`.

I would guess that the most reasonable behavior for auto() in a StrEnum would be to return the name itself, as implemented in the AutoName example at https://docs.python.org/3.10/library/enum.html#using-automatic-values.  I believe that this may just be a matter of copying the corresponding `_generate_next_value_` implementation into the definition of StrEnum?
msg381254 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2020-11-17 16:11
A good idea.

Since the Python opinion of enum members is that they be upper-cased, and every magic string constant I have seen is lower-case, `StrEnum._generate_next_value_` should lower case the name.  Users can substitute their own `_gnv_` for different behavior.
msg382840 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2020-12-10 20:20
New changeset efb13be72cbf49edf591936fafb120fe1b7d59f7 by Ethan Furman in branch 'master':
bpo-42385: [Enum] add `_generate_next_value_` to StrEnum (GH-23735)
https://github.com/python/cpython/commit/efb13be72cbf49edf591936fafb120fe1b7d59f7
msg382842 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2020-12-10 20:21
Thank you for finding that, Antony.
msg382848 - (view) Author: Antony Lee (Antony.Lee) * Date: 2020-12-10 21:28
Thanks for implementing!
History
Date User Action Args
2022-04-11 14:59:38adminsetgithub: 86551
2020-12-10 21:28:39Antony.Leesetnosy: - Antony.Lee
2020-12-10 21:28:33Antony.Leesetmessages: + msg382848
2020-12-10 20:21:34ethan.furmansetstatus: open -> closed
resolution: fixed
messages: + msg382842

stage: patch review -> resolved
2020-12-10 20:20:16ethan.furmansetmessages: + msg382840
2020-12-10 18:56:11ethan.furmansetstage: needs patch -> patch review
pull_requests: + pull_request22594
2020-12-10 18:17:08ethan.furmansettitle: Should enum.auto's behavior be adjusted for StrEnum to return the enum name? -> adjust enum.auto's behavior for StrEnum to return the enum name
stage: patch review -> needs patch
2020-12-10 03:28:47ethan.furmansetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request22587
2020-11-17 16:11:54ethan.furmansetassignee: ethan.furman
type: behavior
messages: + msg381254
stage: needs patch
2020-11-17 10:00:47xtreaksetnosy: + barry, eli.bendersky, ethan.furman
2020-11-17 09:01:11Antony.Leecreate