Title: Make joins symmetric and transitive? · Issue #3257 · python/mypy · GitHub
Open Graph Title: Make joins symmetric and transitive? · Issue #3257 · python/mypy
X Title: Make joins symmetric and transitive? · Issue #3257 · python/mypy
Description: Joins don't have lattice properties with multiple inheritance. Here is an example of where things currently aren't right because joins aren't symmetric: class A: pass class B: pass class C(A, B): pass class D(B, A): pass a = [C(), D()] #...
Open Graph Description: Joins don't have lattice properties with multiple inheritance. Here is an example of where things currently aren't right because joins aren't symmetric: class A: pass class B: pass class C(A, B): p...
X Description: Joins don't have lattice properties with multiple inheritance. Here is an example of where things currently aren't right because joins aren't symmetric: class A: pass class B: pass clas...
Opengraph URL: https://github.com/python/mypy/issues/3257
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Make joins symmetric and transitive?","articleBody":"Joins don't have lattice properties with multiple inheritance. Here is an example of where things currently aren't right because joins aren't symmetric:\r\n\r\n```py\r\nclass A: pass\r\nclass B: pass\r\n\r\nclass C(A, B): pass\r\nclass D(B, A): pass\r\n\r\na = [C(), D()] # List[A]\r\nb = [D(), C()] # List[B]\r\n```\r\n\r\nSimilar examples can we found for transitivity, I believe -- changing the order of things in a list causes a different type to be inferred, which is at least somewhat bad, as it makes mypy feel unpredictable in some cases.\r\n\r\nOne option would be to only follow the first/leftmost base class in case of multiple inheritance, so the both results would be `List[object]`. We can tweak the example to work it consistently while producing useful types:\r\n\r\n```py\r\nclass A: pass\r\nclass B: pass\r\n\r\nclass C(A, B): pass\r\nclass D(A, B): pass\r\n\r\na = [C(), D()] # would be List[A]\r\nb = [D(), C()] # would be List[A]\r\n```\r\n\r\nThough theoretically better, it has some issues:\r\n* This might be confusing for users as well. However, at least we could document the behavior pretty easily and it would be predictable.\r\n* We'd likely need to update typeshed to have base classes in a suitable order.\r\n* Existing code may require additional type annotations. It's unclear what the impact would be.\r\n\r\nAlternatively, we could just not care about lattice properties. I think that joins only affect inferred types and they won't cause a runtime safety issue since we check types after inference. However, we should review all uses of joins in the implementation and try to understand what the implications would be.\r\n\r\nAnother fix would be to generate more union types from joins, but that would likely have a bigger effect. Now that union types aren't as buggy as they used to be, this might be at least worth some experimentation.\r\n\r\nThis issue also affects protocols (https://github.com/python/mypy/pull/3132), and there the situation is much more complicated.","author":{"url":"https://github.com/JukkaL","@type":"Person","name":"JukkaL"},"datePublished":"2017-04-26T16:42:28Z","url":"https://github.com/python/mypy/issues/3257"}
| 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:bcd6d42f-1ee2-dbcd-f4d3-fa2fcf5b82bf |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A318:CEC0A:248BC4E:2FB6999:6AFFF48D |
| html-safe-nonce | 152e6897e8bfb2729486c9c93ed9232b4c3f936bba6052124fa2835d64d4a689 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMzE4OkNFQzBBOjI0OEJDNEU6MkZCNjk5OTo2QUZGRjQ4RCIsInZpc2l0b3JfaWQiOiI3MzMyOTY1NTcyNjgzOTkyNDUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | a8b39bd3f356a771827591f8c3d860a90600d7d97aae5e6b736cfc57cdb1ac5e |
| hovercard-subject-tag | issue:224530725 |
| 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/3257/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6535e058f42cb6227fa14b346895d6cd717dcf2befd3d03e34c943a3a94656ac/python/mypy/issues/3257 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6535e058f42cb6227fa14b346895d6cd717dcf2befd3d03e34c943a3a94656ac/python/mypy/issues/3257 |
| og:image:alt | Joins don't have lattice properties with multiple inheritance. Here is an example of where things currently aren't right because joins aren't symmetric: class A: pass class B: pass class C(A, B): p... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JukkaL |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0a0d8686a27478df474dd7415776a7a080cde8838b3cd92ea7601187572e5729 |
| 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 | 16a11879678aaf97e2a42c33ee70830aa084fa37 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width