Skip to content
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

Enum with str or int Mixin Breaking Change in Python 3.11 #100458

Open
anze3db opened this issue Dec 23, 2022 · 0 comments
Open

Enum with str or int Mixin Breaking Change in Python 3.11 #100458

anze3db opened this issue Dec 23, 2022 · 0 comments
Assignees
Labels
3.11 docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error

Comments

@anze3db
Copy link

anze3db commented Dec 23, 2022

Bug report

Looks like there was a breaking change with the way str and int mixins work with Enums in Python 3.11:

from enum import Enum


class Foo(str, Enum):
    BAR = "bar"

# Python 3.10
f"{Foo.BAR}"  # > bar

# Python 3.11
f"{Foo.BAR}"  # > Foo.BAR

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

Linked PRs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants