Title: Implementation of overloaded function should be automatically typed · Issue #3160 · python/mypy · GitHub
Open Graph Title: Implementation of overloaded function should be automatically typed · Issue #3160 · python/mypy
X Title: Implementation of overloaded function should be automatically typed · Issue #3160 · python/mypy
Description: Without type annotation, implementation of overloaded functions would assume all arguments are of type Any, and so will fail to properly type check the body (that's assuming one has --checked-untyped-defs flag on - otherwise, the body is...
Open Graph Description: Without type annotation, implementation of overloaded functions would assume all arguments are of type Any, and so will fail to properly type check the body (that's assuming one has --checked-untyp...
X Description: Without type annotation, implementation of overloaded functions would assume all arguments are of type Any, and so will fail to properly type check the body (that's assuming one has --checked-u...
Opengraph URL: https://github.com/python/mypy/issues/3160
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Implementation of overloaded function should be automatically typed","articleBody":"Without type annotation, implementation of overloaded functions would assume all arguments are of type `Any`, and so will fail to properly type check the body (that's assuming one has `--checked-untyped-defs` flag on - otherwise, the body is ignored completely).\r\n\r\nBut annotating the implementation of the overloaded function is annoying:\r\n\r\n```\r\nT = TypeVar('T')\r\nclass MyList(Generic[T]):\r\n items: List[T]\r\n\r\n @overload\r\n def __getitem__(self, index: int) -> T:\r\n pass\r\n\r\n @overload\r\n def __getitem__(self, index: slice) -> Sequence[T]:\r\n pass\r\n\r\n def __getitem__(self, index: Union[int, slice]) -> Union[T, Sequence[T]]:\r\n if isinstance(index, int):\r\n ... # Return a T here\r\n elif isinstance(index, slice):\r\n ... # Return a sequence of Ts here\r\n else:\r\n assert False\r\n```\r\n\r\nIn addition, even with this annotation, precise type checking is impossible. For example, if the code returns a `T` instead of `Sequence[T]` by mistake when `index` is a `slice`, it will pass type check.\r\n\r\nI think mypy should automatically type check the implementation several times, once for each of the possible overloaded variants, and each time assume the argument and return types as provided in that variant. It should also prohibit manual type annotation of implementation of overloaded functions to avoid since it would then be worse than redundant.","author":{"url":"https://github.com/pkch","@type":"Person","name":"pkch"},"datePublished":"2017-04-12T20:21:21Z","url":"https://github.com/python/mypy/issues/3160"}
| 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:61e28ddd-0785-2e94-eb90-e03509c7e373 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EC36:2463C6:4FC42F:6B0354:6B00300F |
| html-safe-nonce | 92e66d01f9ebcebb4941029bd757013b5f9276e4d623287829d3904cfe6c4fb4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQzM2OjI0NjNDNjo0RkM0MkY6NkIwMzU0OjZCMDAzMDBGIiwidmlzaXRvcl9pZCI6IjM4MzA4NTkwMDMwMDk3MDgwNDciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c9a9287d04beef12478abd0ca987abd8ba283b5f0545392206431c0a85870194 |
| hovercard-subject-tag | issue:221379325 |
| 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/3160/issue_layout |
| twitter:image | https://opengraph.githubassets.com/cfb381685d0b57feaf30a3a0d7373a3967ff0ed5f0708e789e20795bfde784bd/python/mypy/issues/3160 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/cfb381685d0b57feaf30a3a0d7373a3967ff0ed5f0708e789e20795bfde784bd/python/mypy/issues/3160 |
| og:image:alt | Without type annotation, implementation of overloaded functions would assume all arguments are of type Any, and so will fail to properly type check the body (that's assuming one has --checked-untyp... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | pkch |
| 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