-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python 3.11.0b4 str(enum) giving integer value and not name #94763
Comments
I believe that this is a deliberate behaviour change from previous versions. The Steering Council specifically approved this change; see the penultimate paragraph here regarding aligning |
#22392 does seem somewhat related but it does mention only string enums should use the values and other types use the member name. If this is a change made on purpose that's fine, I just want to know for sure and whether to update my tests. Edit: Sorry you posted just as I was commenting. |
My apologies for the confusion, I need to get the Whats New updated with the Enum changes/additions. |
No worries, so just to confirm this is expected for pretty much any enum types and not just a string enum as mentioned in the linked issue? |
This is (now) the expected behavior for any mixed Enum/Flag defined in the enum module. The expectation is that existing code being replaced with |
@ethanfurman So what is the idiomatic way to get the member name rather than the value? In 3.10 I have: >>> fs.FileType.__mro__
(<enum 'FileType'>, <enum 'IntEnum'>, int, <enum 'Enum'>, object)
>>> str(fs.FileType.Directory)
'FileType.Directory'
>>> repr(fs.FileType.Directory)
'<FileType.Directory: 3>' How do I get |
I know it was intentional, but just as a data point, the breaking changes to |
@pitrou Either change the class OldIntEnum(int, Enum):
"""
use the `classname.membername` str()
"""
pass |
…Options.setFlags. This is a compromise. python/cpython#94763
@ethanfurman I know this is probably water under the bridge now, but I wonder why breaking changes like this are not called out more distinctly in the What's New (e.g. by including the word "breaking")?! We just had code using plain Could breaking changes at least be marked/called out with "breaking" or somesuch? Then it's easier to grep the What's new when, against expectations, a minor version upgrades changes public behaviour. :-( |
Bug report
The
str()
method on Python 3.11.0b4 is outputting the raw integer value not the class name and label that older Python versions do.On Python 3.10 (and older Python 3 versions) this assertion is true. On python 3.11.0b4 the str value is just
1
.The
repr()
is the same as on older versions, just seems likestr()
is affected.Your environment
The text was updated successfully, but these errors were encountered: