Title: Should typing be calling getattr on arbitrary classes? · Issue #113320 · python/cpython · GitHub
Open Graph Title: Should typing be calling getattr on arbitrary classes? · Issue #113320 · python/cpython
X Title: Should typing be calling getattr on arbitrary classes? · Issue #113320 · python/cpython
Description: Bug report Bug description: I was updating my CI to support python3.12 and ran into the following error that isn't present in the 3.12 builds https://github.com/Gobot1234/steam.py/actions/runs/7276342755/job/19825996032 MRE: from enum im...
Open Graph Description: Bug report Bug description: I was updating my CI to support python3.12 and ran into the following error that isn't present in the 3.12 builds https://github.com/Gobot1234/steam.py/actions/runs/7276...
X Description: Bug report Bug description: I was updating my CI to support python3.12 and ran into the following error that isn't present in the 3.12 builds https://github.com/Gobot1234/steam.py/actions/runs/...
Opengraph URL: https://github.com/python/cpython/issues/113320
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Should typing be calling getattr on arbitrary classes? ","articleBody":"# Bug report\r\n\r\n### Bug description:\r\n\r\nI was updating my CI to support python3.12 and ran into the following error that isn't present in the 3.12 builds https://github.com/Gobot1234/steam.py/actions/runs/7276342755/job/19825996032\r\n\r\nMRE:\r\n```python\r\nfrom enum import IntEnum\r\nfrom typing import Protocol\r\n\r\nclass classproperty:\r\n def __init__(self, func):\r\n self.__func__ = func\r\n\r\n def __get__(self, instance, type):\r\n return self.__func__(type)\r\n\r\nclass _CommentThreadType(IntEnum):\r\n WorkshopAccountDeveloper = 2\r\n\r\nclass Commentable(Protocol):\r\n @classproperty\r\n def _COMMENTABLE_TYPE(cls):\r\n return _CommentThreadType[cls.__name__]\r\n```\r\n\r\nTraceback on `main`:\r\n\r\n```pytb\r\nRunning Debug|x64 interpreter...\r\nTraceback (most recent call last):\r\n File \"C:\\Users\\alexw\\coding\\test_protocol.py\", line 14, in \u003cmodule\u003e\r\n class Commentable(Protocol):\r\n ...\u003c2 lines\u003e...\r\n return _CommentThreadType[cls.__name__]\r\n File \"C:\\Users\\alexw\\coding\\cpython\\Lib\\typing.py\", line 1838, in __init__\r\n cls.__callable_proto_members_only__ = all(\r\n ~~~^\r\n callable(getattr(cls, attr, None)) for attr in cls.__protocol_attrs__\r\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n )\r\n ^\r\n File \"C:\\Users\\alexw\\coding\\cpython\\Lib\\typing.py\", line 1839, in \u003cgenexpr\u003e\r\n callable(getattr(cls, attr, None)) for attr in cls.__protocol_attrs__\r\n ~~~~~~~^^^^^^^^^^^^^^^^^\r\n File \"C:\\Users\\alexw\\coding\\test_protocol.py\", line 9, in __get__\r\n return self.__func__(type)\r\n ~~~~~~~~~~~~~^^^^^^\r\n File \"C:\\Users\\alexw\\coding\\test_protocol.py\", line 17, in _COMMENTABLE_TYPE\r\n return _CommentThreadType[cls.__name__]\r\n ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^\r\n File \"C:\\Users\\alexw\\coding\\cpython\\Lib\\enum.py\", line 763, in __getitem__\r\n return cls._member_map_[name]\r\n ~~~~~~~~~~~~~~~~^^^^^^\r\nKeyError: 'Commentable'\r\n```\r\n\r\n\r\nShould typing be more careful about accessing random attributes on classes to prevent these kinds of errors in the future?\r\n\r\n### CPython versions tested on:\r\n\r\n3.12\r\n\r\n### Operating systems tested on:\r\n\r\nmacOS\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-113401\n* gh-113722\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/Gobot1234","@type":"Person","name":"Gobot1234"},"datePublished":"2023-12-20T14:50:35.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":9},"url":"https://github.com/113320/cpython/issues/113320"}
| 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:987cec0a-8c5b-8ab1-dd29-8fe987427642 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B84C:3960C0:47A0B8:657E9D:696A0B8A |
| html-safe-nonce | f424053ae51bfed856c9a6a4aca5610be48483e3b070fd58601d4ea9b45472a7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCODRDOjM5NjBDMDo0N0EwQjg6NjU3RTlEOjY5NkEwQjhBIiwidmlzaXRvcl9pZCI6IjE1NTE3MDAwMjQyODQwMjM2OTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 154ee68c898241ca131796f2e1b660bf4e61f169fd35d1ba9c4c7a86fb925020 |
| hovercard-subject-tag | issue:2050699999 |
| 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/113320/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ad7e426bbd51969e90ea30be0d6462a84a5b8936f6657822a62ea9aacf35a636/python/cpython/issues/113320 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ad7e426bbd51969e90ea30be0d6462a84a5b8936f6657822a62ea9aacf35a636/python/cpython/issues/113320 |
| og:image:alt | Bug report Bug description: I was updating my CI to support python3.12 and ran into the following error that isn't present in the 3.12 builds https://github.com/Gobot1234/steam.py/actions/runs/7276... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Gobot1234 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 699227a00bbb7fe1eec276d2ae1c3a93068bc5ba483bd9dc4b2a27a8f4f2f595 |
| 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 | 7266b2d935baa1c6474b16dd9feaa5ca30607261 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width