You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Enum with str or int Mixin Breaking Change in Python 3.11 #100458
The same goes for Enum classes with the int mixin.
In my project we were relying on Foo.BAR to return the enum value, so this change broke our code. We fixed it by replacing str Enum mixin with the newly added StrEnum class (thanks for that, it's exactly what we needed!).
I think reverting the breaking change would only introduce another breaking change so that's probably not the way to go. But maybe updating the whatsnew page and call out the change there could help people stumbling into this when doing the upgrade. I've found the existing point about this change in the release notes a little bit confusing and I have already opened a PR to try and clear it up a bit: #100387
I've also written a longer blog post about it here, and there has been some lively discussion in r/python.
Your environment
CPython versions tested on: 3.11.0, 3.11.1
Operating system and architecture: MacOS, Ubuntu 22.04
@JosephSBoyle yes, we replaced the str mixin with StrEnum to fix this on our end. If we could let people know about this breaking change in the what's new docs it would save me a lot of head scratching, especially since the current note about this change seems wrong (see my attempt of at least making it a bit more accurate: #100387)
Reacted by JosephSBoyle, Artyom Palvelev, Parker Keller, IKEGAMI Yuto, Flavia Nshemerirwe and Emanuele Iannone
Coincidentally I've also used the mixin approach you describe in professional projects, which suggests that this use is at the very least not uncommon.
As such it makes sense that the docs also suggest a way to achieve the old behaviour, like you say @anze3db. I've added a small suggestion to your PR; hopefully that will help resolve things for others in the same position!
Activity
JosephSBoyle commentedon Dec 25, 2022
@anze3db
StrEnumwas added in 3.11, does that work as a 'slot in' replacement for your use case?docs: https://docs.python.org/3.11/library/enum.html#enum.StrEnum
anze3db commentedon Dec 27, 2022
@JosephSBoyle yes, we replaced the str mixin with
StrEnumto fix this on our end. If we could let people know about this breaking change in the what's new docs it would save me a lot of head scratching, especially since the current note about this change seems wrong (see my attempt of at least making it a bit more accurate: #100387)JosephSBoyle commentedon Dec 27, 2022
Coincidentally I've also used the mixin approach you describe in professional projects, which suggests that this use is at the very least not uncommon.
As such it makes sense that the docs also suggest a way to achieve the old behaviour, like you say @anze3db. I've added a small suggestion to your PR; hopefully that will help resolve things for others in the same position!
anze3db commentedon Dec 27, 2022
Thank you! The text that you added would have helped me a lot when I was figuring out how to fix this 👍
gh-100458: Clarify Enum.__format__() change of mixed-in types in the …
pythongh-100458: Clarify Enum.__format__() change of mixed-in types i…
[3.11] gh-100458: Clarify Enum.__format__() change of mixed-in types …
Merge branch 'main' into inlinecomp2
Tediously update all enum usages to use Enum.KEY.value instead of Enu…
21 remaining items
Update and add support for 3.11 and 3.12 (#902)
Fix issue with enum test caused by breaking change in cpython
[dagster-helm] 3.11 str enum compat (#19113)
[dagster webserver] fix websockets on py3.11 (#19328)
[dagster webserver] fix websockets on py3.11 (#19328)
Replace usage of Enum plus str mixin with StrEnum
Add support for Python 3.11
Add support for Python 3.11
Add support for Python 3.11
Update streams.py
📽️ Olive StrEnumBase IntEnumBase (#1290)
📽️ Olive StrEnumBase IntEnumBase (microsoft#1290)
fix breaking changes to new str-enum mixin behaviour in Py3.11
[buildkite] stop using str Enum (#25874)
fix(python 3.11): Python 3.11+ changed __str__ for enums