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 — gh-100458: Clarify Enum.__format__() change of mixed-in types in the whatsnew/3.11.rst by anze3db · Pull Request #100387 · python/cpython

Conversation

@anze3db

@anze3db anze3db commented Dec 21, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Hey! 👋

Please correct me if I'm wrong, but the description of the change Enum.format() change in 3.11.rst doesn't seem accurate. The behavior in older Python versions was to return the member's value and not the member's key as is currently stated. Example code:

from enum import Enum


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


print("{}".format(Foo.BAR))


class Foo(int, Enum):
    BAR = 1


print("{}".format(Foo.BAR))

Running this on Python 3.10 prints:

bar
1

And not

BAR
BAR

as the changelog states:

Changed Enum.format() (the default for format(), str.format() and f-strings) of enums with mixed-in types (e.g. int, str) to also include the class name in the output, not just the member’s key. This matches the existing behavior of enum.Enum.str(), returning e.g. 'AnEnum.MEMBER' for an enum AnEnum(str, Enum) instead of just 'MEMBER'.

I noticed this because we were using the str mixin with all Enum classes as a hack to get to the value without needing to write Foo.BAR.value 🫣 The new behavior in Python 3.11 broke our code and the current phrasing in the changelog makes it feel this was just a minor bugfix. Should this change be a bit more prominent since it can be a breaking change?

By the way, thank you for adding StrEnum, it's exactly what we needed!

PS: Not sure if this needs a GitHub issue number, it's not exactly a typo, but it's still a minor change. I'm happy to open an issue if needed. Issue linked below. Also let me know if I need to open the PR against any other branches as well. 🙇

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bebound, artemisart, and baybatu reacted with thumbs up emoji
All reactions
  • 👍 3 reactions
@anze3db
Clarify Enum.__format__() change of mixed-in types
e51f55c
@bedevere-bot bedevere-bot added awaiting review docs Documentation in the Doc dir skip news labels Dec 21, 2022
@ghost

ghost commented Dec 21, 2022 •
edited by ghost
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.
CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kumaraditya303 kumaraditya303 assigned ethanfurman Dec 23, 2022
@anze3db anze3db mentioned this pull request Dec 23, 2022
Enum with str or int Mixin Breaking Change in Python 3.11 #100458
Closed
@anze3db anze3db changed the title Clarify Enum.__format__() change of mixed-in types in the whatsnew/3.11.rst gh-100458: Clarify Enum.__format__() change of mixed-in types in the whatsnew/3.11.rst Dec 23, 2022
JosephSBoyle
JosephSBoyle reviewed Dec 27, 2022
View reviewed changes
Comment thread Doc/whatsnew/3.11.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

anze3db and others added 4 commits December 27, 2022 14:47
@anze3db @JosephSBoyle
Point users to StrEnum or IntEnum for old formatting behavior
4ccc0fe
Co-authored-by: JosephSBoyle <[email protected]>
@anze3db
Merge branch 'main' into main
3311e3d
@anze3db
Split into multiple ines
0d265a0
@anze3db
Fix small typo
5f30054
@anze3db

anze3db commented Dec 27, 2022

Copy link
Copy Markdown
Contributor Author

@JosephSBoyle thank you! I've added your changes. Let me know if there is anything else needed from my side. Should I also open a PR against the 3.11 branch?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@anze3db
anze3db requested a review from JosephSBoyle December 27, 2022 15:08
@ethanfurman ethanfurman added 3.11 only security fixes 3.12 only security fixes labels Dec 27, 2022
@ethanfurman

ethanfurman commented Dec 27, 2022

Copy link
Copy Markdown
Member

@anze3db No need, once this is committed a backport PR will be automatically created.

anze3db reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AlexWaygood AlexWaygood added the needs backport to 3.11 only security fixes label Dec 27, 2022
JosephSBoyle
JosephSBoyle approved these changes Dec 27, 2022
View reviewed changes
@bedevere-bot bedevere-bot added awaiting core review and removed awaiting review labels Dec 27, 2022
@anze3db

anze3db commented Jan 31, 2023

Copy link
Copy Markdown
Contributor Author

@JosephSBoyle there was more than a month of inactivity on this PR 😞 Anything I can do to help this getting merged?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JosephSBoyle

JosephSBoyle commented Jan 31, 2023

Copy link
Copy Markdown
Contributor

Hi @anze3db, I'm not a maintainer so perhaps this is a better question for @AlexWaygood. If the assigned reviewer is busy perhaps another reviewer can be assigned.

anze3db reacted with confused emoji
All reactions
  • 😕 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AlexWaygood
AlexWaygood self-requested a review January 31, 2023 09:39
@Bktero

Bktero commented Mar 22, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Will this PR finds its way to the next version of Python?

Further question: is this change documented here https://docs.python.org/3/library/enum.html ? I can't spot it...

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ethanfurman
ethanfurman requested changes Mar 22, 2023
View reviewed changes

@ethanfurman ethanfurman left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My apologies -- I didn't get the [Submit Review] button pressed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

anze3db reacted with hooray emoji
All reactions
  • 🎉 1 reaction
Comment thread Doc/whatsnew/3.11.rst Outdated
(the default for :func:`format`, :meth:`str.format` and :term:`f-string`\s)
of enums with mixed-in types (e.g. :class:`int`, :class:`str`)
to also include the class name in the output, not just the member's key.
to include the class name and member key in the output, not the member's value.

@ethanfurman ethanfurman Feb 1, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
to include the class name and member key in the output, not the member's value.
to show the class name and member name in the output, instead of the member's value.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

anze3db reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Doc/whatsnew/3.11.rst Outdated
to also include the class name in the output, not just the member's key.
to include the class name and member key in the output, not the member's value.
This matches the existing behavior of :meth:`enum.Enum.__str__`,
returning e.g. ``'AnEnum.MEMBER'`` for an enum ``AnEnum(str, Enum)``

@ethanfurman ethanfurman Feb 1, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
returning e.g. ``'AnEnum.MEMBER'`` for an enum ``AnEnum(str, Enum)``
returning e.g. ``'AnEnum.MEMBER'`` for an enum ``AnEnum(str, Enum)``.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

anze3db reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Doc/whatsnew/3.11.rst Outdated
This matches the existing behavior of :meth:`enum.Enum.__str__`,
returning e.g. ``'AnEnum.MEMBER'`` for an enum ``AnEnum(str, Enum)``
instead of just ``'MEMBER'``.
instead of the member's value. Those wishing to keep the old formatting behavior

@ethanfurman ethanfurman Feb 1, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
instead of the member's value. Those wishing to keep the old formatting behavior
Those wishing to keep the old formatting behavior

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

anze3db reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@bedevere-bot bedevere-bot added awaiting changes and removed awaiting core review labels Mar 22, 2023
@bedevere-bot

bedevere-bot commented Mar 22, 2023

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AlexWaygood
AlexWaygood removed their request for review March 22, 2023 16:54
@anze3db
Address PR feedback
bee67ca
@anze3db

anze3db commented Mar 22, 2023

Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot added awaiting change review and removed awaiting changes labels Mar 22, 2023
@bedevere-bot

bedevere-bot commented Mar 22, 2023

Copy link
Copy Markdown

Thanks for making the requested changes!

@ethanfurman: please review the changes made to this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot
bedevere-bot requested a review from ethanfurman March 22, 2023 19:07
@anze3db

anze3db commented Apr 13, 2023

Copy link
Copy Markdown
Contributor Author

@ethanfurman just a friendly reminder to re-review this if you have the time, thanks!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ethanfurman
update prose
6aed4ca
ethanfurman
ethanfurman reviewed Apr 18, 2023
View reviewed changes

@ethanfurman ethanfurman left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did some rewriting in an attempt to make it clearer.

Thoughts on the new changes?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
ethanfurman
ethanfurman approved these changes May 1, 2023
View reviewed changes
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting change review labels May 1, 2023
@ethanfurman
ethanfurman merged commit e665563 into python:main May 1, 2023
@miss-islington

miss-islington commented May 1, 2023

Copy link
Copy Markdown
Contributor

Thanks @anze3db for the PR, and @ethanfurman for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the awaiting merge label May 1, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 1, 2023
@anze3db @JosephSBoyle
@ethanfurman @miss-islington
pythongh-100458: Clarify Enum.__format__() change of mixed-in types i…
ff58045
…n the whatsnew/3.11.rst (pythonGH-100387)

(cherry picked from commit e665563)

Co-authored-by: Anže Pečar <[email protected]>
Co-authored-by: JosephSBoyle <[email protected]>
Co-authored-by: Ethan Furman <[email protected]>
@bedevere-bot

bedevere-bot commented May 1, 2023

Copy link
Copy Markdown

GH-104060 is a backport of this pull request to the 3.11 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label May 1, 2023
ethanfurman added a commit that referenced this pull request May 1, 2023
@miss-islington @anze3db
@JosephSBoyle @ethanfurman
[3.11] gh-100458: Clarify Enum.__format__() change of mixed-in types …
723aacb
…in the whatsnew/3.11.rst (GH-100387) (GH-104060)

Co-authored-by: Anže Pečar <[email protected]>
Co-authored-by: JosephSBoyle <[email protected]>
Co-authored-by: Ethan Furman <[email protected]>
carljm added a commit to carljm/cpython that referenced this pull request May 1, 2023
@carljm
Merge branch 'main' into inlinecomp2
1274e2b
* main: (463 commits)
  pythongh-104057: Fix direct invocation of test_super (python#104064)
  pythongh-87092: Expose assembler to unit tests (python#103988)
  pythongh-97696: asyncio eager tasks factory (python#102853)
  pythongh-84436: Immortalize in _PyStructSequence_InitBuiltinWithFlags() (pythongh-104054)
  pythongh-104057: Fix direct invocation of test_module (pythonGH-104059)
  pythongh-100458: Clarify Enum.__format__() change of mixed-in types in the whatsnew/3.11.rst (pythonGH-100387)
  pythongh-104018: disallow "z" format specifier in %-format of byte strings (pythonGH-104033)
  pythongh-104016: Fixed off by 1 error in f string tokenizer (python#104047)
  pythonGH-103629: Update Unpack's repr in compliance with PEP 692 (python#104048)
  pythongh-102799: replace sys.exc_info by sys.exception in inspect and traceback modules (python#104032)
  Fix typo in "expected" word in few source files (python#104034)
  pythongh-103824: fix use-after-free error in Parser/tokenizer.c (python#103993)
  pythongh-104035: Do not ignore user-defined `__{get,set}state__` in slotted frozen dataclasses (python#104041)
  pythongh-104028: Reduce object creation while calling callback function from gc (pythongh-104030)
  pythongh-104036: Fix direct invocation of test_typing (python#104037)
  pythongh-102213: Optimize the performance of `__getattr__` (pythonGH-103761)
  pythongh-103895: Improve how invalid `Exception.__notes__` are displayed (python#103897)
  Adjust expression from `==` to `!=` in alignment with the meaning of the paragraph. (pythonGH-104021)
  pythongh-88496: Fix IDLE test hang on macOS (python#104025)
  Improve int test coverage (python#104024)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ethanfurman ethanfurman ethanfurman approved these changes
+1 more reviewer
@JosephSBoyle JosephSBoyle JosephSBoyle approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@ethanfurman ethanfurman

Labels

3.11 only security fixes 3.12 only security fixes docs Documentation in the Doc dir skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@anze3db @ethanfurman @JosephSBoyle @Bktero @bedevere-bot @miss-islington @AlexWaygood
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — 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.