Title: Allow subclassing without supertyping · Issue #241 · python/typing · GitHub
Open Graph Title: Allow subclassing without supertyping · Issue #241 · python/typing
X Title: Allow subclassing without supertyping · Issue #241 · python/typing
Description: This issue comes from python/mypy#1237. I'll try to make a summary of the discussion here Some one reported an issue with an artificial example (python/mypy#1237 (comment)): class Foo: def factory(self) -> str: return 'Hello' class Bar(F...
Open Graph Description: This issue comes from python/mypy#1237. I'll try to make a summary of the discussion here Some one reported an issue with an artificial example (python/mypy#1237 (comment)): class Foo: def factory(...
X Description: This issue comes from python/mypy#1237. I'll try to make a summary of the discussion here Some one reported an issue with an artificial example (python/mypy#1237 (comment)): class Foo: def fact...
Opengraph URL: https://github.com/python/typing/issues/241
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Allow subclassing without supertyping","articleBody":"This issue comes from python/mypy#1237. I'll try to make a summary of the discussion here\n\nSome one reported an issue with an artificial example (https://github.com/python/mypy/issues/1237#issue-136162181):\n\n``` python\nclass Foo:\n def factory(self) -> str:\n return 'Hello'\n\nclass Bar(Foo):\n def factory(self) -> int:\n return 10\n```\n\nand then with the following stub files (https://github.com/python/mypy/issues/1237#issuecomment-188710925):\n\n``` python\nclass QPixmap(QPaintDevice):\n def swap(self, other: 'QPixmap') -> None: ...\n\nclass QBitmap(QPixmap):\n def swap(self, other: 'QBitmap') -> None: ...\n```\n\nWhich mypy currently reports as erroneous: `Argument 1 of \"swap\" incompatible with supertype \"QPixmap\"`\n\nThese were initially was argued to be a correct error because they violate Liskov Substitution Principle (the same case by a change of return type, the second is a covariant argument change). The problem in this scenario is that the actual classes are not meant to be substituted (the first example is actually a wrapper for a non-virtual C++ function so they're not substitutable, and the second aren't supposed to be mixed together, just reuse part of the code). (see https://github.com/python/mypy/issues/1237#issuecomment-189490903)\n\nThere was also a suggestion that allow covariant args explicitly (in the same way that Eiffel allows it and adds a runtime check) with a decorator\n\n``` python\nclass QBitmap(QPixmap):\n @covariant_args\n def swap(self, other: 'QBitmap') -> None: ...\n```\n\nMy proposal instead was add what some dialects of Eiffel call \"non-conforming inheritance\" (\"conforms\" is the Eiffel word for what PEP-483 calls \"is-consistent-with\"). It is essentially a mechanism to use subclassing just as a way to get the implementation from the superclass without creating a subtyping relation between them. See https://github.com/python/mypy/issues/1237#issuecomment-231199419 for a detailed explanation.\n\nThe proposal is to haven `Implementation` in typing so you can write:\n\n``` python\nclass QBitmap(Implementation[QPixmap]):\n def swap(self, other: 'QBitmap') -> None: ...\n```\n\nwhich just defines a `QBitmap` class with all the mothods copied from `QPixmap`, but without making one a subtype of the other. In runtime we can just make `Implementation[QPixmap] == QPixmap`\n","author":{"url":"https://github.com/dmoisset","@type":"Person","name":"dmoisset"},"datePublished":"2016-07-08T12:57:10Z","url":"https://github.com/python/typing/issues/241"}
| 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:b5939bd9-3fe2-17a4-8d6f-e62d201f0c61 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 99C6:3DCBB0:38A074:4F9459:6B006F68 |
| html-safe-nonce | e2f0c072b24958842963e50b97ffdc48c259ca56f69b1f7b49ca53d7efce29d9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5OUM2OjNEQ0JCMDozOEEwNzQ6NEY5NDU5OjZCMDA2RjY4IiwidmlzaXRvcl9pZCI6IjE5NzYwNDY3MjczNDU1MDAwMDgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 587418e61bbddaa71e676493e3d9e6ba2836dfc6edef2058c9cc21c1c75c11fa |
| hovercard-subject-tag | issue:164525166 |
| 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/typing/241/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4c444dab6bb8b39688ce88c8aba67a7492dc696bb8d8f62f51e2f325160cb861/python/typing/issues/241 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4c444dab6bb8b39688ce88c8aba67a7492dc696bb8d8f62f51e2f325160cb861/python/typing/issues/241 |
| og:image:alt | This issue comes from python/mypy#1237. I'll try to make a summary of the discussion here Some one reported an issue with an artificial example (python/mypy#1237 (comment)): class Foo: def factory(... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dmoisset |
| hostname | github.com |
| expected-hostname | github.com |
| None | 6527e91c60c0b29d16606ff32ac5df8ecdc37a2a62205ea057a14d7762c870fa |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typing git https://github.com/python/typing.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 24604008 |
| octolytics-dimension-repository_nwo | python/typing |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24604008 |
| octolytics-dimension-repository_network_root_nwo | python/typing |
| 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 | 46f1cd2ae3cd8ae1a81019b5d619742e76f13bbd |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width