Title: Handling de-facto positional-only arguments with overloads · Issue #5235 · python/mypy · GitHub
Open Graph Title: Handling de-facto positional-only arguments with overloads · Issue #5235 · python/mypy
X Title: Handling de-facto positional-only arguments with overloads · Issue #5235 · python/mypy
Description: In my PR for updating the mypy docs, @gvanrossum pointed out that one of my examples didn't typecheck -- the simplified repro was this: class A: pass class B: pass @overload def foo(a: int) -> A: pass @overload def foo(a: int, b: int) ->...
Open Graph Description: In my PR for updating the mypy docs, @gvanrossum pointed out that one of my examples didn't typecheck -- the simplified repro was this: class A: pass class B: pass @overload def foo(a: int) -> A: p...
X Description: In my PR for updating the mypy docs, @gvanrossum pointed out that one of my examples didn't typecheck -- the simplified repro was this: class A: pass class B: pass @overload def foo(a: int) -&g...
Opengraph URL: https://github.com/python/mypy/issues/5235
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Handling de-facto positional-only arguments with overloads","articleBody":"In my [PR for updating the mypy docs](https://github.com/python/mypy/pull/5229), @gvanrossum pointed out that one of my examples didn't typecheck -- the simplified repro was this:\r\n\r\n class A: pass\r\n class B: pass\r\n\r\n @overload\r\n def foo(a: int) -> A: pass\r\n @overload\r\n def foo(a: int, b: int) -> B: pass\r\n def foo(*args: int) -> Union[A, B]:\r\n raise NotImplementedError()\r\n\r\nAfter debugging, I realized that the checks are actually technically correct: the overloads suggest that running `foo(a=1, b=2)` is type-safe; that call will crash at runtime.\r\n\r\nThis feels a bit annoying though, so I'm thinking it'd be nice if we could relax these checks -- basically, allow the existence of \"de-facto positional-only arguments\".\r\n\r\nI'm thinking one way we can do this is to:\r\n\r\n1. Relax the overload definition checks so they ignore the argument names\r\n2. Perform an extra check every time we call an overload: if the overload has an implementation, we check and see names match and report a (custom) error if they don't.\r\n\r\nSo under this proposal, `foo` would continue to type-check, but we'd report an error if somebody tried doing `foo(a=1, a=2)`.\r\n\r\nThe main disadvantage is that this would cause feature disparity with overloads in stubs since stubs don't allow you to include an implementation. We could either live with this or maybe allow users to add an implementations with empty bodies in stubs if we really want to maintain parity.\r\n\r\nThoughts? (I wanted to file an issue to get consensus/see if anybody is able to come up with a better solution before I start implementation.)","author":{"url":"https://github.com/Michael0x2a","@type":"Person","name":"Michael0x2a"},"datePublished":"2018-06-19T02:21:23Z","url":"https://github.com/python/mypy/issues/5235"}
| 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:ab29c87c-3a29-3b5d-09cf-bab8f70f5b0f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E668:5875E:28E9368:37BF4A1:6B0049BB |
| html-safe-nonce | cc8980f4ed34eafa38df10e9595ac6168335537ee35cf5bd1112b416f57b0c3b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNjY4OjU4NzVFOjI4RTkzNjg6MzdCRjRBMTo2QjAwNDlCQiIsInZpc2l0b3JfaWQiOiI3MDY0NzQ5MTIyMzg0ODQxMTQ3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | f853937543552692ccbb33e513217c264a6cc48df94d568a3292950e0d893ba6 |
| hovercard-subject-tag | issue:333496617 |
| 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/5235/issue_layout |
| twitter:image | https://opengraph.githubassets.com/91ab550a92467b8670e151fc5a4944089924f0641bc2ad2fa830e41c23c7bf52/python/mypy/issues/5235 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/91ab550a92467b8670e151fc5a4944089924f0641bc2ad2fa830e41c23c7bf52/python/mypy/issues/5235 |
| og:image:alt | In my PR for updating the mypy docs, @gvanrossum pointed out that one of my examples didn't typecheck -- the simplified repro was this: class A: pass class B: pass @overload def foo(a: int) -> A: p... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Michael0x2a |
| hostname | github.com |
| expected-hostname | github.com |
| None | f9517bf360d46638a1e5e7daee7158842fe5ef43c9000afa0e127564a7c2f39b |
| 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 | b27c5dde30676028abd5c5fc53ce5c9b625f8281 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width