Title: enum.global_enum: `cls_name` undefined in `global_str` · Issue #93100 · python/cpython · GitHub
Open Graph Title: enum.global_enum: `cls_name` undefined in `global_str` · Issue #93100 · python/cpython
X Title: enum.global_enum: `cls_name` undefined in `global_str` · Issue #93100 · python/cpython
Description: Bug report In acf7403 (#30582), @ethanfurman implemented a global_enum decorator, replacing the __str__ of an enum with enum.global_str: cpython/Lib/enum.py Lines 1638 to 1645 in 760ec89 def global_str(self): """ use enum_name instead of...
Open Graph Description: Bug report In acf7403 (#30582), @ethanfurman implemented a global_enum decorator, replacing the __str__ of an enum with enum.global_str: cpython/Lib/enum.py Lines 1638 to 1645 in 760ec89 def global...
X Description: Bug report In acf7403 (#30582), @ethanfurman implemented a global_enum decorator, replacing the __str__ of an enum with enum.global_str: cpython/Lib/enum.py Lines 1638 to 1645 in 760ec89 def global...
Opengraph URL: https://github.com/python/cpython/issues/93100
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"enum.global_enum: `cls_name` undefined in `global_str`","articleBody":"**Bug report**\r\n\r\nIn acf7403f9baea3ae1119fc6b4a3298522188bf96 (#30582), @ethanfurman implemented a `global_enum` decorator, replacing the `__str__` of an enum with `enum.global_str`:\r\n\r\nhttps://github.com/python/cpython/blob/760ec8940aabd6a7fc471bd913ea1ac501cc604b/Lib/enum.py#L1638-L1645\r\n\r\n(This was later reverted in 42a64c03ec5c443f2a5c2ee4284622f5d1f5326c and reintroduced in 83d544b9292870eb44f6fca37df0aa351c4ef83a, but I believe the code to be the same).\r\n\r\nIf the `._name_` attribute is `None`, this uses `cls_name`, but that's not defined anywhere in that function!\r\n\r\nHere is a (somewhat contrived) example:\r\n\r\n```python\r\nimport enum\r\n\r\n@enum.global_enum\r\nclass EnumTest(enum.Enum):\r\n VAL = 1\r\n\r\nEnumTest.VAL._name_ = None\r\n\r\nprint(str(VAL))\r\n```\r\n\r\nthis fails with:\r\n\r\n```pytb\r\nTraceback (most recent call last):\r\n File \"/home/florian/tmp/x.py\", line 9, in \u003cmodule\u003e\r\n print(str(VAL))\r\n ^^^^^^^^\r\n File \"/usr/lib/python3.11/enum.py\", line 1646, in global_str\r\n return \"%s(%r)\" % (cls_name, self._value_)\r\n ^^^^^^^^\r\nNameError: name 'cls_name' is not defined\r\n```\r\n\r\n(Found by running `flake8` over `Lib/` out of curiosity, see https://github.com/python/cpython/issues/93010#issuecomment-1133402591)\r\n\r\n**Your environment**\r\n\r\n- CPython versions tested on: Python 3.11.0b1\r\n- Operating system and architecture: Archlinux x86_64","author":{"url":"https://github.com/The-Compiler","@type":"Person","name":"The-Compiler"},"datePublished":"2022-05-23T10:18:45.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/93100/cpython/issues/93100"}
| 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:b671c3d7-3320-039e-4499-1077115ab65c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A730:A7972:17EBE77:2111D9D:696A9FD3 |
| html-safe-nonce | 6baaa25c7baf16a72affc0f959d9b64ae013f2cd84d7d013fa8f3c7f8154b721 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNzMwOkE3OTcyOjE3RUJFNzc6MjExMUQ5RDo2OTZBOUZEMyIsInZpc2l0b3JfaWQiOiIyNzQ1MTU1MTgzOTYyNjYwODE5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 8a031230c969b0ea6df3b4a2873c7303c93613388b866a3a92f5cf360ccd8132 |
| hovercard-subject-tag | issue:1244934122 |
| 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/93100/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d956d9029f4c4b4b4dc19b6bec5b49dbdac6e99de1cff7ef52a6be54d2dd73b0/python/cpython/issues/93100 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d956d9029f4c4b4b4dc19b6bec5b49dbdac6e99de1cff7ef52a6be54d2dd73b0/python/cpython/issues/93100 |
| og:image:alt | Bug report In acf7403 (#30582), @ethanfurman implemented a global_enum decorator, replacing the __str__ of an enum with enum.global_str: cpython/Lib/enum.py Lines 1638 to 1645 in 760ec89 def global... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | The-Compiler |
| hostname | github.com |
| expected-hostname | github.com |
| None | a51f97dbb9326f71c08ecb61577457d543c602124d1a2672871258ef37ac5261 |
| 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 | 4bd0eac606c70914085176ef312ebdcd97a8cdf1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width