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: str() and repr() of enum different in Python 3.11 from Python <= 3.10
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Dutcho, barry, ethan.furman, gregory.p.smith
Priority: normal Keywords:

Created on 2021-10-16 10:58 by Dutcho, last changed 2022-04-11 14:59 by admin.

Messages (6)
msg404069 - (view) Author: (Dutcho) Date: 2021-10-16 10:58
See below example, which shows Python 3.11 repr(enum) == Python 3.10 str(enum).

The enum module documentation lists various enhancements in 3.11, but not this.
And the what's new? documentation of 3.11 doesn't mention enum at all.

Either this is by intent, and then should be documented incl. breaking old code depending on representation, or is by accident, and then merits fixing (which is what alphas are for).

> py -3.10 enum_test.py
3.10.0 (tags/v3.10.0:b494f59, Oct  4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)]
ABC.a ABC.b ABC.c ABC.a <ABC.a: 1>

> py -3.11 enum_test.py
3.11.0a1 (tags/v3.11.0a1:7c12e48, Oct  5 2021, 15:38:19) [MSC v.1929 64 bit (AMD64)]
a b c a ABC.a

> more enum_test.py
import enum
import sys


class ABC(enum.Enum):
    a = enum.auto()
    b = enum.auto()
    c = enum.auto()


print(sys.version)
print(*ABC, str(ABC.a), repr(ABC.a))
msg404072 - (view) Author: (Dutcho) Date: 2021-10-16 11:49
perhaps related to https://bugs.python.org/issue44559 ?
msg404238 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2021-10-18 22:55
This doesn't seem right, given that PEP 663 has not been approved by the SC yet:

3.9.7 (default, Oct 13 2021, 06:45:31) 
[Clang 13.0.0 (clang-1300.0.29.3)]
ABC.a ABC.b ABC.c ABC.a <ABC.a: 1>
|main=|@presto[~/projects/python/cpython:1058]% python3.10 /tmp/foo.py 
3.10.0 (default, Oct 13 2021, 06:45:00) [Clang 13.0.0 (clang-1300.0.29.3)]
ABC.a ABC.b ABC.c ABC.a <ABC.a: 1>
|main=|@presto[~/projects/python/cpython:1059]% ./python.exe /tmp/foo.py 
3.11.0a1+ (heads/main:6a533a4238, Oct 18 2021, 15:30:20) [Clang 13.0.0 (clang-1300.0.29.3)]
a b c a ABC.a

In 3.10, the behavior was reverted back to 3.9, so it makes sense that those two have the same output.  Python 3.11 should as well, for now at least, until the SC approves PEP 663
msg404241 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2021-10-18 23:03
Enum was reverted at the last minute for 3.10.  I would like to keep the changes in 3.11 so they get more exposure.

I have asked the SC a few times for thoughts about PEP 663, including whether an information PEP needs formal approval, but still haven't heard back.

At any rate, I do not have the band-width to undo and then redo all the changes in the 3.11 Enum.
msg404270 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2021-10-19 07:04
We just need https://github.com/python/cpython/pull/27010 to be done on main to roll it back.

str and repr changes are quite painful to foist upon users existing code and tests.
msg404335 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2021-10-19 18:55
I can see why Ethan might be overwhelmed by reverting this change.  I tried to merge in his branch but failed, so I'm chucking that work and will try again.
History
Date User Action Args
2022-04-11 14:59:51adminsetgithub: 89656
2021-10-19 18:55:43barrysetmessages: + msg404335
2021-10-19 07:04:37gregory.p.smithsetnosy: + gregory.p.smith
messages: + msg404270
2021-10-18 23:03:37ethan.furmansetmessages: + msg404241
2021-10-18 22:55:17barrysetnosy: + barry, ethan.furman
messages: + msg404238
2021-10-16 11:49:20Dutchosetmessages: + msg404072
2021-10-16 11:44:00Dutchosettitle: str() and repr() of enum different in Python 3.11 from from Python <= 3.10 -> str() and repr() of enum different in Python 3.11 from Python <= 3.10
2021-10-16 10:58:57Dutchocreate