Title: What to do when the runtime lies? · Issue #11141 · python/typeshed · GitHub
Open Graph Title: What to do when the runtime lies? · Issue #11141 · python/typeshed
X Title: What to do when the runtime lies? · Issue #11141 · python/typeshed
Description: I've been cleaning up inheritance mismatches. I've found that several modules with a C implementation fudge the module name of their classes. For example: ReferenceType is a class defined in the _weakref C implementation, and then import...
Open Graph Description: I've been cleaning up inheritance mismatches. I've found that several modules with a C implementation fudge the module name of their classes. For example: ReferenceType is a class defined in the _w...
X Description: I've been cleaning up inheritance mismatches. I've found that several modules with a C implementation fudge the module name of their classes. For example: ReferenceType is a class defined i...
Opengraph URL: https://github.com/python/typeshed/issues/11141
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"What to do when the runtime lies?","articleBody":"I've been cleaning up inheritance mismatches. I've found that several modules with a C implementation fudge the module name of their classes. For example:\r\n\r\n`ReferenceType` is a class defined in the `_weakref` C implementation, and then imported from there into the `weakref` module. Because it's a C implementation, it's free to declare it's own qualified name, and calls itself `weakref.ReferenceType`: https://github.com/python/cpython/blob/main/Objects/weakrefobject.c#L368C1-L368C1\r\n\r\nThe intention, I believe, being that this class canonically lives in the `weakref` module, and the fact that it's being defined in `_weakref` is an implementation detail which is hidden at runtime. Typeshed declares the class in `_weakref.pyi`, which means it gets a qualified name of `_weakref.ReferenceType`\r\n\r\nI can see two possible arguments:\r\n\r\n - Typeshed should continue to follow the layout of implementation over the declared implementation. e.g. `ReferenceType` is defined in `_weakref` originally, so that's the correct place for it.\r\n\r\nOR \r\n\r\n - Typeshed should follow the declared implementation over the layout. e.g. `ReferenceType` considers itself to live in the `weakref` module, that's where the majority of users will get it from, so that's the correct place for it.\r\n\r\n\r\nThis pattern pops up in a lot of places: in `_ast`, `_decimal`, and `_sqlite3` are some of the others I've noticed. I suspect the current state of typeshed is inconsistent on this issue, since not all modules that have a C implementation currently have a `_foo.pyi` stub file. \r\n\r\nIs there a consensus among typeshed's maintainers here? I'm a little biased towards option 2 at the moment, since I'm trying to make as many inheritances match as I can, but I think there's a good argument for either side, and this is, in the end, a very minor issue with not much practical effect.","author":{"url":"https://github.com/tungol","@type":"Person","name":"tungol"},"datePublished":"2023-12-10T21:09:56Z","url":"https://github.com/python/typeshed/issues/11141"}
| 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:04b69448-f7c9-e799-c26c-94d1adef32c9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BBDE:22FAD4:7A01B4:A29E00:6B003ABB |
| html-safe-nonce | d5e1012f123a71b1f57886f096cb2fadd7a484852176ea47fe5b3390a7a7dcca |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQkRFOjIyRkFENDo3QTAxQjQ6QTI5RTAwOjZCMDAzQUJCIiwidmlzaXRvcl9pZCI6IjcyNjExMTAxNzgxMzk4ODAxMjMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 7a41343e020c01932b78a36242394d5256a22ce695d157387648ebd3cdd80f25 |
| hovercard-subject-tag | issue:2034534885 |
| 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/typeshed/11141/issue_layout |
| twitter:image | https://opengraph.githubassets.com/75fbdd38c4a5792ad97e7d4a0d184ce168945358517b6351466825a185487f7a/python/typeshed/issues/11141 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/75fbdd38c4a5792ad97e7d4a0d184ce168945358517b6351466825a185487f7a/python/typeshed/issues/11141 |
| og:image:alt | I've been cleaning up inheritance mismatches. I've found that several modules with a C implementation fudge the module name of their classes. For example: ReferenceType is a class defined in the _w... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | tungol |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typeshed git https://github.com/python/typeshed.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 31696383 |
| octolytics-dimension-repository_nwo | python/typeshed |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 31696383 |
| octolytics-dimension-repository_network_root_nwo | python/typeshed |
| 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