Title: Allow non-descriptor callables in `functools.singledispatchmethod` · Issue #140873 · python/cpython · GitHub
Open Graph Title: Allow non-descriptor callables in `functools.singledispatchmethod` · Issue #140873 · python/cpython
X Title: Allow non-descriptor callables in `functools.singledispatchmethod` · Issue #140873 · python/cpython
Description: Bug report Bug description: When a non-descriptor callable (such as a lambda or a class instance) is registered as a handler, singledispatchmethod unconditionally attempts to call the __get__ method on that handler during dispatch. This ...
Open Graph Description: Bug report Bug description: When a non-descriptor callable (such as a lambda or a class instance) is registered as a handler, singledispatchmethod unconditionally attempts to call the __get__ metho...
X Description: Bug report Bug description: When a non-descriptor callable (such as a lambda or a class instance) is registered as a handler, singledispatchmethod unconditionally attempts to call the __get__ metho...
Opengraph URL: https://github.com/python/cpython/issues/140873
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Allow non-descriptor callables in `functools.singledispatchmethod`","articleBody":"# Bug report\n\n### Bug description:\n\nWhen a non-descriptor callable (such as a lambda or a class instance) is registered as a handler, `singledispatchmethod` unconditionally attempts to call the `__get__` method on that handler during dispatch.\nThis results in an AttributeError, because non-descriptor callables do not have a __get__ method.\nThis behavior directly violates the explicit guarantee in `singledispatchmethod`'s own [docstring](https://github.com/python/cpython/blob/main/Lib/functools.py#L1014), which states that it does handle non-descriptor callables.\n\n```python\nimport functools\n\nclass MyCallable:\n def __call__(self, host_self, arg):\n return f\"Handled {arg} via MyCallable\"\n\nclass Host:\n @functools.singledispatchmethod\n def my_method(self, arg):\n return f\"Base handling for {arg}\"\n\ncallable_instance = MyCallable()\nHost.my_method.register(int, callable_instance)\n\n\nh = Host()\n\nh.my_method(123)\n```\n\n```python\nAttributeError: 'MyCallable' object has no attribute '__get__'. Did you mean: '__ge__'?\n```\n\n\n### CPython versions tested on:\n\n3.12\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-140884\n* gh-141523\n* gh-141710\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/T90REAL","@type":"Person","name":"T90REAL"},"datePublished":"2025-11-01T04:24:04.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/140873/cpython/issues/140873"}
| 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:31252883-3051-983c-c1a7-dcd17f4e7175 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9088:2F21B4:49197:5C4A9:696AFB6D |
| html-safe-nonce | bcb3029573fcd309a965fd11ccaf1295714e480043076c96369abc6a17426df3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MDg4OjJGMjFCNDo0OTE5Nzo1QzRBOTo2OTZBRkI2RCIsInZpc2l0b3JfaWQiOiI1MDE2NjQwNDk5MjEyODExMTE3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 63e8189e520171044547d2aeae9c6a0b1d41e22b3435d43bc0cfaf7804df1062 |
| hovercard-subject-tag | issue:3577197347 |
| 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/140873/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b243da9ddc21bb923ab2646be5a28051155f0c8f81f14171fb43a3fd81a0b5cb/python/cpython/issues/140873 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b243da9ddc21bb923ab2646be5a28051155f0c8f81f14171fb43a3fd81a0b5cb/python/cpython/issues/140873 |
| og:image:alt | Bug report Bug description: When a non-descriptor callable (such as a lambda or a class instance) is registered as a handler, singledispatchmethod unconditionally attempts to call the __get__ metho... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | T90REAL |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| 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 | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width