Title: Overzealous Optimization For `isinstance` · Issue #144873 · python/cpython · GitHub
Open Graph Title: Overzealous Optimization For `isinstance` · Issue #144873 · python/cpython
X Title: Overzealous Optimization For `isinstance` · Issue #144873 · python/cpython
Description: Bug report Bug description: The custom __instancecheck__ dunder method allows full customization (described in the Data model). However, it produces a spurious result: class CustomIsInstanceMeta(type): def __instancecheck__(cls, instance...
Open Graph Description: Bug report Bug description: The custom __instancecheck__ dunder method allows full customization (described in the Data model). However, it produces a spurious result: class CustomIsInstanceMeta(ty...
X Description: Bug report Bug description: The custom __instancecheck__ dunder method allows full customization (described in the Data model). However, it produces a spurious result: class CustomIsInstanceMeta(ty...
Opengraph URL: https://github.com/python/cpython/issues/144873
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Overzealous Optimization For `isinstance`","articleBody":"# Bug report\n\n### Bug description:\n\nThe custom `__instancecheck__` dunder method allows full customization (described in the [Data model](https://docs.python.org/3.14/reference/datamodel.html#customizing-instance-and-subclass-checks)).\n\nHowever, it produces a spurious result:\n\n```python\nclass CustomIsInstanceMeta(type):\n def __instancecheck__(cls, instance: object) -> bool:\n return type(instance) is int\n\nclass CustomIsInstance(metaclass=CustomIsInstanceMeta):\n ...\n\nclass CustomIsInstanceSubclass(CustomIsInstance):\n ...\n\n\nprint(isinstance(5, CustomIsInstance)) # True\nprint(isinstance(CustomIsInstance(), CustomIsInstance)) # True (should be False)\nprint(isinstance(CustomIsInstanceSubclass(), CustomIsInstance)) # False\n```\n\nThis is caused by:\nhttps://github.com/python/cpython/blob/23c488d6197191d355be6733699a295c20806932/Objects/abstract.c#L2641-L2644\nwhich is invalid in this case.\n\n\nThis is a reframing of #79264 (request to fix documentation)\n\n### CPython versions tested on:\n\n3.13\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-144874\n* gh-144997\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/George-Ogden","@type":"Person","name":"George-Ogden"},"datePublished":"2026-02-16T12:17:01Z","url":"https://github.com/python/cpython/issues/144873"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:1eed0ac3-06de-b9b8-279f-6e84daebfdc8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C5A4:1050BD:173CB9A:1EB88D0:6B020978 |
| html-safe-nonce | 978e038ae30a3088e87c55cb8bccf525dabcb1d97d815acc22316bfe438493a5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNUE0OjEwNTBCRDoxNzNDQjlBOjFFQjg4RDA6NkIwMjA5NzgiLCJ2aXNpdG9yX2lkIjoiNTY5MzE4MDA4NzM3MTA2Mjk2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 03d76eca7a308762ef321e597d4ec286ae57c2a70d51f0f3cacdd7cebe8e8c6d |
| hovercard-subject-tag | issue:3947485592 |
| 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/144873/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4df6467a9ad275bdb771cfece23ba45d31ee4e972216b4bcf73449e5813c5970/python/cpython/issues/144873 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4df6467a9ad275bdb771cfece23ba45d31ee4e972216b4bcf73449e5813c5970/python/cpython/issues/144873 |
| og:image:alt | Bug report Bug description: The custom __instancecheck__ dunder method allows full customization (described in the Data model). However, it produces a spurious result: class CustomIsInstanceMeta(ty... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | George-Ogden |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width