Title: gh-100458: Clarify Enum.__format__() change of mixed-in types in the whatsnew/3.11.rst by anze3db · Pull Request #100387 · python/cpython · GitHub
Open Graph Title: gh-100458: Clarify Enum.__format__() change of mixed-in types in the whatsnew/3.11.rst by anze3db · Pull Request #100387 · python/cpython
X Title: gh-100458: Clarify Enum.__format__() change of mixed-in types in the whatsnew/3.11.rst by anze3db · Pull Request #100387 · python/cpython
Description: 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: gh-100458
Open Graph Description: 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 memb...
X Description: 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 ...
Opengraph URL: https://github.com/python/cpython/pull/100387
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/checks(.:format) |
| route-controller | pull_requests |
| route-action | checks |
| fetch-nonce | v2:4d1e7004-ffcf-f390-15ad-dfb1dc088bed |
| current-catalog-service-hash | 87dc3bc62d9b466312751bfd5f889726f4f1337bdff4e8be7da7c93d6c00a25a |
| request-id | EC60:A457C:326EB4:426E7B:69697B97 |
| html-safe-nonce | 7c983db25b24931aa3600f44177addde48d0f9fe917c2fc99aead5feaf105e85 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQzYwOkE0NTdDOjMyNkVCNDo0MjZFN0I6Njk2OTdCOTciLCJ2aXNpdG9yX2lkIjoiMjA4MDYzMDYwNjkwNTU3MjI0NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 26c20820cd3496d11a318b0921e8c096a1500b6d36c119d2b807a98cc9a450ee |
| hovercard-subject-tag | pull_request:1173099441 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,checks,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/100387/checks |
| twitter:image | https://avatars.githubusercontent.com/u/513444?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/513444?s=400&v=4 |
| og:image:alt | 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 memb... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | f33e4b94c8824ab2b434d82a94139432fb5ebee9df4b75304140ad22508c4a77 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive full-width full-width-p-0 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 48f380098b30acbb700b04f1724481ca10d574fc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width