Title: Bound instance methods fail to satisfy `runtime_checkable` `Protocol` · Issue #127059 · python/cpython · GitHub
Open Graph Title: Bound instance methods fail to satisfy `runtime_checkable` `Protocol` · Issue #127059 · python/cpython
X Title: Bound instance methods fail to satisfy `runtime_checkable` `Protocol` · Issue #127059 · python/cpython
Description: Bug report Bug description: #103034 added some protections around isinstance checks of runtime_checkable Protocols using inspect.getattr_static. This uses inspect._check_instance which uses object.__getattribute__(obj, "__dict__"), which...
Open Graph Description: Bug report Bug description: #103034 added some protections around isinstance checks of runtime_checkable Protocols using inspect.getattr_static. This uses inspect._check_instance which uses object....
X Description: Bug report Bug description: #103034 added some protections around isinstance checks of runtime_checkable Protocols using inspect.getattr_static. This uses inspect._check_instance which uses object....
Opengraph URL: https://github.com/python/cpython/issues/127059
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Bound instance methods fail to satisfy `runtime_checkable` `Protocol`","articleBody":"# Bug report\n\n### Bug description:\n\n#103034 added some protections around `isinstance` checks of `runtime_checkable` `Protocols` using `inspect.getattr_static`. This [uses](https://github.com/python/cpython/blob/37c57dfad12744608091653fd753a1f770e2479b/Lib/inspect.py#L1733) `inspect._check_instance` which [uses](https://github.com/python/cpython/blob/main/Lib/inspect.py#L1669) `object.__getattribute__(obj, \"__dict__\")`, which fails for bound instance methods (although `obj.__dict__` does work), so they cannot fulfill `runtime_checkable` `Protocols` anymore.\n\n```\nfrom typing import Protocol, runtime_checkable\n\n\n@runtime_checkable\nclass Labelled(Protocol):\n label: str\n\n\nclass A:\n def f(self):\n pass\n\n\nA.f.label = \"f\"\n\na = A()\nprint(a.f.__dict__) # {'label': 'f'}\nprint(object.__getattribute__(a.f, \"__dict__\")) # AttributeError\n\nassert isinstance(a.f, Labelled) # AssertionError\n```\n\nIs this an intended/known change? Could it be noted in the changelog [here](https://docs.python.org/3/whatsnew/3.12.html#typing) as an example of case that will no longer work?\n\n---\n\nCreated from https://github.com/python/cpython/pull/103034#issuecomment-2488670252\ncc @AlexWaygood \n\n### CPython versions tested on:\n\n3.12\n\n### Operating systems tested on:\n\nLinux","author":{"url":"https://github.com/GDYendell","@type":"Person","name":"GDYendell"},"datePublished":"2024-11-20T14:32:36.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/127059/cpython/issues/127059"}
| 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:03a6b3c8-a272-5a47-3177-7ea8578f9b6c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E2B6:25F5D0:293663:38297E:6969A9F8 |
| html-safe-nonce | 0bf7b23b7bc0038ece80dda5fc08c9b362794d16e2f9cb144dfd4d98d4beb310 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMkI2OjI1RjVEMDoyOTM2NjM6MzgyOTdFOjY5NjlBOUY4IiwidmlzaXRvcl9pZCI6IjMyMDUzNDczNjE5MjczMDk4MTYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | ed828191848491ef3978bd153da187be923836425e453a0b8e0280bb8e67a26f |
| hovercard-subject-tag | issue:2676048882 |
| 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/127059/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6f674a7c296287fbe61314886e0e1bbacd759a9adde53dd4b8a5deabebb1b78a/python/cpython/issues/127059 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6f674a7c296287fbe61314886e0e1bbacd759a9adde53dd4b8a5deabebb1b78a/python/cpython/issues/127059 |
| og:image:alt | Bug report Bug description: #103034 added some protections around isinstance checks of runtime_checkable Protocols using inspect.getattr_static. This uses inspect._check_instance which uses object.... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | GDYendell |
| hostname | github.com |
| expected-hostname | github.com |
| None | 24c4c97a2d520cb286b35e1a4c22d7a4df3c26a2fa28dd7cdf0e65db327b4de7 |
| 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 | 124667f43168afb6c9c03b7c02eb5b1d2e1be3d9 |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width