Title: How should we annotate cooperative inheritance? · Issue #8769 · python/mypy · GitHub
Open Graph Title: How should we annotate cooperative inheritance? · Issue #8769 · python/mypy
X Title: How should we annotate cooperative inheritance? · Issue #8769 · python/mypy
Description: Optional static typing for Python. Contribute to python/mypy development by creating an account on GitHub.
Open Graph Description: Optional static typing for Python. Contribute to python/mypy development by creating an account on GitHub.
X Description: Optional static typing for Python. Contribute to python/mypy development by creating an account on GitHub.
Opengraph URL: https://github.com/python/mypy
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"How should we annotate cooperative inheritance?","articleBody":"Consider annotating this example of cooperative multiple inheritance:\r\n```python\r\nfrom typing import Any\r\n\r\n\r\nclass Hidden:\r\n\r\n def __init__(self, z: float, **kwargs: Any):\r\n super().__init__(**kwargs)\r\n self.z = z\r\n\r\n\r\nclass Base:\r\n\r\n def __init__(self, x: int, **kwargs: Any):\r\n super().__init__(**kwargs)\r\n self.x = x\r\n\r\n\r\nclass Inherited(Base):\r\n\r\n def __init__(self, y: int, **kwargs: Any):\r\n super().__init__(**kwargs)\r\n self.y = y\r\n\r\n\r\nclass Final(Inherited, Hidden):\r\n pass\r\n```\r\nMyPy gives errors because of the super-calls, which is addressed by https://github.com/python/mypy/issues/4001.\r\n\r\nIt would be nice for `Inherited` to ensure in its super-call that `x` has the right type, which is the topic of https://github.com/python/mypy/issues/4441 although it would also be nice for `Final`'s constructor to only accept `x`, `y`, and `z`. I can't find any issue for that.\r\n\r\nThis example is done with `__init__`, but the problem can occur in any such “augmenting” method pattern. It is not restricted to `__init__`. This augmenting pattern always needs a top level method in some class. In `__init__`'s case, it's in `object`.\r\n\r\nOne idea is to have a special annotation on `**kwargs`, for example, `typing.Collector`? MyPy could then figure out the necessary arguments and their types in all derived classes. An inherited class would only be allowed to explicitly forward variables accepted by parents, but they should be able to forward anything. MyPy would make a best effort to ensure that all required arguments get in somehow.\r\n\r\nI recognize that not everyone is a fan of cooperative MI, but I personally think it's quite beautiful. I would love to see MyPy handle it elegantly.","author":{"url":"https://github.com/NeilGirdhar","@type":"Person","name":"NeilGirdhar"},"datePublished":"2020-05-04T09:46:35Z","url":"https://github.com/python/mypy/issues/8769"}
| 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 | /:user_id/:repository/issues/:id(.:format) |
| route-controller | issues |
| route-action | show |
| fetch-nonce | v2:6471f6a3-e20e-be94-b581-43303bb845eb |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AF30:23FDF9:1F9BAB9:2B0B142:6B001FEE |
| html-safe-nonce | 2cdf4e211d49588550fbd975aa47657900a54a05fa83ff1639a78020c9b474dc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRjMwOjIzRkRGOToxRjlCQUI5OjJCMEIxNDI6NkIwMDFGRUUiLCJ2aXNpdG9yX2lkIjoiMTkxNzY3NTI3ODUyNDQ4OTcxMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d199cede05c8959edc5339deba1dafe9f8f638166401f8909ef072e5ba7d5cd3 |
| hovercard-subject-tag | repository:7053637 |
| 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/python/mypy/issues/8769 |
| twitter:image | https://opengraph.githubassets.com/f79ae5636353a0db17350af0a02700f2e9c3bbcf096f9450bf0c369c77cd1022/python/mypy |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f79ae5636353a0db17350af0a02700f2e9c3bbcf096f9450bf0c369c77cd1022/python/mypy |
| og:image:alt | Optional static typing for Python. Contribute to python/mypy development by creating an account on GitHub. |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| turbo-cache-control | no-cache |
| 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 | 44c658b24abf00491fb7ae5f56d42c9f38cbeab2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width