Title: Change in semantics and much worse performance for enum members. · Issue #93910 · python/cpython · GitHub
Open Graph Title: Change in semantics and much worse performance for enum members. · Issue #93910 · python/cpython
X Title: Change in semantics and much worse performance for enum members. · Issue #93910 · python/cpython
Description: Given the enum: class Colours(Enum): RED = 1 In Python 3.9 and 3.10: >>> Colours.__dict__["RED"] is Colours.RED True >>> Colours.RED.RED
Open Graph Description: Given the enum: class Colours(Enum): RED = 1 In Python 3.9 and 3.10: >>> Colours.__dict__["RED"] is Colours.RED True >>> Colours.RED.RED
X Description: Given the enum: class Colours(Enum): RED = 1 In Python 3.9 and 3.10: >>> Colours.__dict__["RED"] is Colours.RED True >>> Colours.RED.RED <Colours.RED: 1> In Python...
Opengraph URL: https://github.com/python/cpython/issues/93910
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Change in semantics and much worse performance for enum members.","articleBody":"Given the enum:\r\n```Python\r\nclass Colours(Enum):\r\n RED = 1\r\n```\r\nIn Python 3.9 and 3.10:\r\n```Python\r\n\u003e\u003e\u003e Colours.__dict__[\"RED\"] is Colours.RED\r\nTrue\r\n\u003e\u003e\u003e Colours.RED.RED\r\n\u003cColours.RED: 1\u003e\r\n\r\n```\r\nIn Python 3.11:\r\n```Python\r\n\u003e\u003e\u003e Colours.__dict__[\"RED\"] is Colours.RED\r\nFalse\r\n\u003e\u003e\u003e Colours.RED.RED\r\nTraceback (most recent call last):\r\n File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\r\n File \"/home/mark/repos/cpython/Lib/enum.py\", line 198, in __get__\r\n raise AttributeError(\r\n ^^^^^^^^^^^^^^^^^^^^^\r\nAttributeError: \u003cenum 'Colours'\u003e member has no attribute 'RED'\r\n```\r\n\r\nWhile these might seem like minor semantic changes, there is also a large performance impact.\r\nLookup of `Colours.RED` is simple and efficient in 3.10, but involves a lot of indirection and dispatching through the `enum.property` class in 3.11.\r\nThe performance impact is likely to get worse in 3.12, as we optimize more kinds of attributes.\r\n\r\nIntroduced in https://github.com/python/cpython/commit/c314e60388282d9829762fb6c30b12e2807caa19, I believe.\r\n\r\n@pablogsal \r\n@ethanfurman \n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-103236\n* gh-103299\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/markshannon","@type":"Person","name":"markshannon"},"datePublished":"2022-06-16T15:57:50.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":83},"url":"https://github.com/93910/cpython/issues/93910"}
| 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:8d094464-88cb-41bd-2447-d7cd62fbe0d2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DE78:371600:22C884E:2F9EB47:696AC303 |
| html-safe-nonce | ac3350ce5c70b6fe0cb35c757ec22cb31c0225bcfc909a735d3fdfe8d6d13189 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERTc4OjM3MTYwMDoyMkM4ODRFOjJGOUVCNDc6Njk2QUMzMDMiLCJ2aXNpdG9yX2lkIjoiMjU5MjU3MTcwNzY1MzUzODU2MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 65ff330c7df6b795fea653d6abd1db718d02213154b1166d8a2cd36025f1e3e0 |
| hovercard-subject-tag | issue:1273764974 |
| 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/93910/issue_layout |
| twitter:image | https://opengraph.githubassets.com/baebe0bf07af7ecdc5b7ab1c1980e9e44a7943e9a09cee1fc2eeccbee679eb71/python/cpython/issues/93910 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/baebe0bf07af7ecdc5b7ab1c1980e9e44a7943e9a09cee1fc2eeccbee679eb71/python/cpython/issues/93910 |
| og:image:alt | Given the enum: class Colours(Enum): RED = 1 In Python 3.9 and 3.10: >>> Colours.__dict__["RED"] is Colours.RED True >>> Colours.RED.RED |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | markshannon |
| hostname | github.com |
| expected-hostname | github.com |
| None | 986b6a1d774985095564e64d6963d11f094da3d0e2bfda2ab1a27d63662eb033 |
| 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 | 89ad2112b9c4e11df6a0c13c8c1f8eedd36b0977 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width