Title: Let plugins customize class MRO · Issue #4527 · python/mypy · GitHub
Open Graph Title: Let plugins customize class MRO · Issue #4527 · python/mypy
X Title: Let plugins customize class MRO · Issue #4527 · python/mypy
Description: The Python metaclass data model allows the mro() method to be overloaded. This is a genuinely useful feature for dealing with metaclasses whose classes must support inheritance. See "Example" below. I wrote a mypy plugin for type-checkin...
Open Graph Description: The Python metaclass data model allows the mro() method to be overloaded. This is a genuinely useful feature for dealing with metaclasses whose classes must support inheritance. See "Example" below...
X Description: The Python metaclass data model allows the mro() method to be overloaded. This is a genuinely useful feature for dealing with metaclasses whose classes must support inheritance. See "Example&q...
Opengraph URL: https://github.com/python/mypy/issues/4527
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Let plugins customize class MRO","articleBody":"The Python metaclass data model allows the `mro()` method to be overloaded. This is a genuinely useful feature for dealing with metaclasses whose classes must support inheritance. See \"Example\" below.\r\n\r\nI wrote a `mypy` plugin for type-checking instances of my metaclass. I was able to model its semantics almost correctly with the existing plugin hooks, except for one thing — customizing the MRO.\r\n\r\nThe best way I can get my type-checker unblocked is by adding a plugin hook for customizing the MRO. My idea is roughly this:\r\n - Move `calculate_class_mro` to be a member of `SemanticAnalyzerPass2`\r\n - Add a plugin hook that gets to customize the computed MRO.\r\n\r\n@JukkaL, does this sound like a feature you would take?\r\n\r\n\r\nExample of needing to customize the MRO:\r\n - My metaclass `M` injects a implementation-detail base `M_classname_base` into each class it creates. `M`'s semantics demand that `M_classname_base` be at the very end of the MRO (to allow overloading of its features).\r\n - Let us define `class A(metaclass=M)` and `class B(A)`.\r\n - Each class injects its own base: `M_A_base` and `M_B_base`. That means that `B` actually has both implementation-detail bases.\r\n - Unfortunately, `M_A_base` and `M_B_base` conflict, and `M_B_base` ends up **after** `M_A_base` in the MRO, which is the opposite of what you want (child must overload parent, not vice versa). \r\n - At runtime, `M.mro()` can simply remove the `A`-produced base from `B`'s MRO, and all is well.\r\n - In current `mypy`, removing `M_A_base` from `B`'s MRO seems impossible.\r\n\r\nCc: @carljm, if you're curious.\r\n","author":{"url":"https://github.com/snarkmaster","@type":"Person","name":"snarkmaster"},"datePublished":"2018-01-31T23:41:35Z","url":"https://github.com/python/mypy/issues/4527"}
| 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:0ecf99b8-1a8f-cecb-cd9a-a423056bb4a6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DAAA:22E601:4D024A:679C81:6B002EF0 |
| html-safe-nonce | cbcc1bbd538dd8abc3d9be2a245661778dc547db8f8db44c0829512fd00cd128 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQUFBOjIyRTYwMTo0RDAyNEE6Njc5QzgxOjZCMDAyRUYwIiwidmlzaXRvcl9pZCI6IjEzMTE0OTIyMTQzNjY0MTY2MjQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c03b9d621fbdac4ca6328c09af78068b466edc4101563411024053bbfe44953f |
| hovercard-subject-tag | issue:293352700 |
| 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/mypy/4527/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2dde1cfe892ccc73ef18b1a6488f19c271c6c84eb64acf097998f2d3c48af0ad/python/mypy/issues/4527 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2dde1cfe892ccc73ef18b1a6488f19c271c6c84eb64acf097998f2d3c48af0ad/python/mypy/issues/4527 |
| og:image:alt | The Python metaclass data model allows the mro() method to be overloaded. This is a genuinely useful feature for dealing with metaclasses whose classes must support inheritance. See "Example" below... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | snarkmaster |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/mypy git https://github.com/python/mypy.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 7053637 |
| octolytics-dimension-repository_nwo | python/mypy |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 7053637 |
| octolytics-dimension-repository_network_root_nwo | python/mypy |
| 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 | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width