Title: `Enum.__str__` change could be improved in What's New · Issue #98250 · python/cpython · GitHub
Open Graph Title: `Enum.__str__` change could be improved in What's New · Issue #98250 · python/cpython
X Title: `Enum.__str__` change could be improved in What's New · Issue #98250 · python/cpython
Description: #30582 (in 3.11) introduced a change to Enum.__str__ so that it shows the enum name and the member name, whereas prior it only included the member name. This could be a breaking change in some cases. As an example in real world code, the...
Open Graph Description: #30582 (in 3.11) introduced a change to Enum.__str__ so that it shows the enum name and the member name, whereas prior it only included the member name. This could be a breaking change in some case...
X Description: #30582 (in 3.11) introduced a change to Enum.__str__ so that it shows the enum name and the member name, whereas prior it only included the member name. This could be a breaking change in some case...
Opengraph URL: https://github.com/python/cpython/issues/98250
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`Enum.__str__` change could be improved in What's New","articleBody":"https://github.com/python/cpython/pull/30582 (in 3.11) introduced a [change](https://github.com/python/cpython/pull/30582/files#diff-007214cd4321f2b3600c085a1b9abe8c6f05662421ff232fb42ee77dafc85920L49) to `Enum.__str__` so that it shows the enum name and the member name, whereas prior it only included the member name.\r\n\r\nThis could be a breaking change in some cases. As an example in real world code, the Azure CLI uses enums for the acceptable values of command-line flags, and then uses `str` on the enum to generate the string that is passed to the subprocess as arguments.\r\n\r\nFor example, this [enum](https://github.com/Azure/azure-cli/blob/dev/src/azure-cli/azure/cli/command_modules/sql/custom.py#L643) is used to define a \"compute model\":\r\n\r\n```\r\nclass ComputeModelType(str, Enum):\r\n\r\n provisioned = \"Provisioned\"\r\n serverless = \"Serverless\"\r\n```\r\n\r\nAnd then it's used [here to construct arguments for a subprocess](https://github.com/Azure/azure-cli/blob/dev/src/azure-cli/azure/cli/command_modules/sql/tests/latest/test_sql_commands.py#L857):\r\n\r\n```\r\nself.cmd('sql db update -g {} --server {} --name {} --compute-model {}'\r\n .format(resource_group, server, database_name, compute_model_serverless),\r\n```\r\n\r\nThe changelog entry for this change just says:\r\n\r\n```\r\nIntEnum / IntFlag / StrEnum fixes: these now inherit from ReprEnum so the str() output now matches format() output, which is the data types’ (so both str(AnIntEnum.ONE) and format(AnIntEnum.ONE) is equal to '1').\r\n```\r\n\r\nThis is unlikely to be easily findable for users running into this change, since `StrEnum` doesn't exist in Python 3.10, and it's a little obscure. I would suggest:\r\n\r\n\u003e The default str() of an Enum has changed to include both Enum name and the member name (`Enum.MEMBER`), whereas before it was just the member name. To continue to use the old behavior, inherit from `IntEnum` or `StrEnum`.\r\n\r\nDoes this make sense? Are there other cases I'm missing? Happy to file a PR, but thought I would get some discussion first.","author":{"url":"https://github.com/mdboom","@type":"Person","name":"mdboom"},"datePublished":"2022-10-13T20:41:22.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/98250/cpython/issues/98250"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:4a562996-93fa-3e99-4a6d-da058a33f81a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B83E:10FD0C:256DF9:3298B3:69696776 |
| html-safe-nonce | 4299a0106c893e8e4bcebb94c6d83679d7c003b8b121559aab1b1e98b7805d2b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCODNFOjEwRkQwQzoyNTZERjk6MzI5OEIzOjY5Njk2Nzc2IiwidmlzaXRvcl9pZCI6IjYyODg5MDExMTA0MDc3MTg3NzQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 994f946175d3c859e829b1e5ddde5a5f2b4a34e3d6e1accbc322a3054f5cecda |
| hovercard-subject-tag | issue:1408399797 |
| github-keyboard-shortcuts | repository,issues,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/_view_fragments/issues/show/python/cpython/98250/issue_layout |
| twitter:image | https://opengraph.githubassets.com/df63cfdd73b0c15527a7a1c564bf2be6b12b68df8ae3d7d1de51c09f1d4429be/python/cpython/issues/98250 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/df63cfdd73b0c15527a7a1c564bf2be6b12b68df8ae3d7d1de51c09f1d4429be/python/cpython/issues/98250 |
| og:image:alt | #30582 (in 3.11) introduced a change to Enum.__str__ so that it shows the enum name and the member name, whereas prior it only included the member name. This could be a breaking change in some case... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mdboom |
| hostname | github.com |
| expected-hostname | github.com |
| None | c6f193beb8ff08443adc07685d75302ab8aaf0a135f6e251c3ff3112c8deb881 |
| 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 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ec4d88fbe7ed62446d90b0a6d8e6db4248a8f8b8 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width