Title: Allow @overload outside stubs · Issue #1136 · python/mypy · GitHub
Open Graph Title: Allow @overload outside stubs · Issue #1136 · python/mypy
X Title: Allow @overload outside stubs · Issue #1136 · python/mypy
Description: Mypy does not consider the stub file for the module it is currently type-checking (and doing so was apparently considered and rejected recently). However, @overload as defined in the PEP is only allowed to appear in stubs, which implies ...
Open Graph Description: Mypy does not consider the stub file for the module it is currently type-checking (and doing so was apparently considered and rejected recently). However, @overload as defined in the PEP is only al...
X Description: Mypy does not consider the stub file for the module it is currently type-checking (and doing so was apparently considered and rejected recently). However, @overload as defined in the PEP is only al...
Opengraph URL: https://github.com/python/mypy/issues/1136
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Allow @overload outside stubs","articleBody":"Mypy does not consider the stub file for the module it is currently type-checking (and doing so was apparently [considered and rejected](https://mail.python.org/pipermail/python-ideas/2016-January/037704.html) recently). However, `@overload` as defined in the PEP is only allowed to appear in stubs, which implies a requirement for type checkers to consider a module's own stubs when type checking it. Otherwise, the ability to type check a module which defines an overloaded function is limited.\n\nMy motivating example:\n\n```\n@overload\ndef utf8(s: None) -> None: ...\n@overload\ndef utf8(s: AnyStr) -> bytes: ...\n```\n\nThis could be expressed as `def utf8(s: Optional[AnyStr]) -> Optional[bytes]`, but I'm trying to capture the fact that if the argument is not None then the result is also guaranteed not to be None, so it doesn't introduce unnecessary `Optional`-ness. (Is there a way to express this with a `TypeVar`? I don't see one). I can put the overloads in a stub for the benefit of external callers of this module, but then I need to put _all_ the type information for this module in the stub and can't type check it internally (I could duplicate all the non-overload type info in the module itself and get partial coverage). I could also put overloaded functions in their own tiny modules to minimize the impact, but that just feels silly.\n","author":{"url":"https://github.com/bdarnell","@type":"Person","name":"bdarnell"},"datePublished":"2016-01-17T17:37:22Z","url":"https://github.com/python/mypy/issues/1136"}
| 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:a086cd4b-964a-62bc-1609-1811e90940c8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 95DA:278022:11FAA8C:179FADB:6B000CCB |
| html-safe-nonce | 2fffc9166eacee2d0575d814d7826fcf05b5f3b98966f8d4c266a0508dc2cbfd |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NURBOjI3ODAyMjoxMUZBQThDOjE3OUZBREI6NkIwMDBDQ0IiLCJ2aXNpdG9yX2lkIjoiMzQ2OTUzMjY4MTUyNjU3ODM3OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f387412f224c69203eee96d56f86e4c7356b37bb45cda71308beed18bfc5860a |
| hovercard-subject-tag | issue:127110730 |
| 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/1136/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b3bef475f665789ecc9e684980e20b034b17e188484abf07ec4d9947620270f0/python/mypy/issues/1136 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b3bef475f665789ecc9e684980e20b034b17e188484abf07ec4d9947620270f0/python/mypy/issues/1136 |
| og:image:alt | Mypy does not consider the stub file for the module it is currently type-checking (and doing so was apparently considered and rejected recently). However, @overload as defined in the PEP is only al... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bdarnell |
| hostname | github.com |
| expected-hostname | github.com |
| None | cf7ee0062053ad9eb05b6e5de57bd96c2055708bcbada4144946b5ec129cf1d7 |
| 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 | 9cab7de176a56362d2aabcbb4d1e07e846eba8a0 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width