GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Enum with `str` or `int` Mixin Breaking Change in Python 3.11 · Issue #100458 · python/cpython

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

New issue
Copy link
New issue
Copy link
Closed
batfish/pybatfish
#902
batfish/pybatfish#902
Closed
Enum with str or int Mixin Breaking Change in Python 3.11#100458
batfish/pybatfish
#902
Copy link
Assignees
ethanfurman
Labels
3.11only security fixesonly security fixesdocsDocumentation in the Doc dirDocumentation in the Doc dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@anze3db
anze3db
opened on Dec 23, 2022
Issue body actions

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

  • gh-100458: Clarify Enum.__format__() change of mixed-in types in the whatsnew/3.11.rst #100387
  • [3.11] gh-100458: Clarify Enum.__format__() change of mixed-in types in the whatsnew/3.11.rst (GH-100387) #104060
Reacted by Juan Estevez, Chase Sterling, JosephSBoyle, Andrey Semakin, Vianney Mixtur, lisez, Noam Miko Tamir, jkbrzt, Jérémy Anger, Tomasz Wesołowski and 16 more

Activity

Next
  1. anze3db
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Dec 23, 2022
  2. AlexWaygood
    assigned
    ethanfurman
    on Dec 23, 2022
  3. AlexWaygood
    added
    docsDocumentation in the Doc dirDocumentation in the Doc dir
    3.11only security fixesonly security fixes
    on Dec 23, 2022
  4. JosephSBoyle commented on Dec 25, 2022

    @JosephSBoyle
    JosephSBoyle
    on Dec 25, 2022
    Contributor
    More actions

    @anze3db StrEnum was 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

  5. anze3db commented on Dec 27, 2022

    @anze3db
    anze3db
    on Dec 27, 2022
    ContributorAuthor
    More actions

    @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
  6. JosephSBoyle commented on Dec 27, 2022

    @JosephSBoyle
    JosephSBoyle
    on Dec 27, 2022
    Contributor
    More actions

    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!

  7. anze3db commented on Dec 27, 2022

    @anze3db
    anze3db
    on Dec 27, 2022
    ContributorAuthor
    More actions

    Thank you! The text that you added would have helped me a lot when I was figuring out how to fix this 👍

  8. ethanfurman
    added this to enum issueson Mar 30, 2023
  9. ethanfurman
    moved this to Research in enum issueson Mar 30, 2023
  10. ethanfurman
    added a commit that references this issue on May 1, 2023

    gh-100458: Clarify Enum.__format__() change of mixed-in types in the …

    e665563
  11. miss-islington
    added a commit that references this issue on May 1, 2023

    pythongh-100458: Clarify Enum.__format__() change of mixed-in types i…

    ff58045
  12. ethanfurman
    added a commit that references this issue on May 1, 2023

    [3.11] gh-100458: Clarify Enum.__format__() change of mixed-in types …

    723aacb
  13. carljm
    added a commit that references this issue on May 1, 2023

    Merge branch 'main' into inlinecomp2

    1274e2b
  14. gordonhart
    added a commit that references this issue on May 10, 2023

    Tediously update all enum usages to use Enum.KEY.value instead of Enu…

    3e9baba
  15. 21 remaining items

  16. dhalperi
    added a commit that references this issue on Dec 16, 2023

    Update and add support for 3.11 and 3.12 (#902)

    e238298
  17. sanjacob
    added a commit that references this issue on Jan 8, 2024

    Fix issue with enum test caused by breaking change in cpython

    5c57bd1
  18. alangenfeld
    added a commit that references this issue on Jan 9, 2024

    [dagster-helm] 3.11 str enum compat (#19113)

    c98cae5
  19. alangenfeld
    added a commit that references this issue on Jan 19, 2024

    [dagster webserver] fix websockets on py3.11 (#19328)

    962b4f2
  20. PedramNavid
    added a commit that references this issue on Jan 26, 2024

    [dagster webserver] fix websockets on py3.11 (#19328)

    587298f
  21. lqc
    added 4 commits that reference this issue on Apr 25, 2024

    Replace usage of Enum plus str mixin with StrEnum

    7dfa7f7

    Add support for Python 3.11

    3bc2ad9

    Add support for Python 3.11

    06fba20

    Add support for Python 3.11

    8ed0fc4
  22. DLT1412
    added a commit that references this issue on Jun 19, 2024

    Update streams.py

    dac0832
  23. jambayk
    added a commit that references this issue on Aug 9, 2024

    📽️ Olive StrEnumBase IntEnumBase (#1290)

    213ac7a
  24. DavitGrigoryan132
    added a commit that references this issue on Aug 14, 2024

    📽️ Olive StrEnumBase IntEnumBase (microsoft#1290)

    0db8b95
  25. giancarloromeo
    added a commit that references this issue on Aug 16, 2024

    fix breaking changes to new str-enum mixin behaviour in Py3.11

    2be8b05
  26. alangenfeld
    added a commit that references this issue on Nov 12, 2024

    [buildkite] stop using str Enum (#25874)

    2941dfc
  27. pierresouchay
    added a commit that references this issue on Aug 9, 2025

    fix(python 3.11): Python 3.11+ changed __str__ for enums

    a19b9c9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @ethanfurman
    ethanfurman

Labels

3.11only security fixesonly security fixesdocsDocumentation in the Doc dirDocumentation in the Doc dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Projects

  • enum issues
    Status
    Done
    Show more project fields

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.