Title: @overload outside stubs · Issue #72 · python/typing · GitHub
Open Graph Title: @overload outside stubs · Issue #72 · python/typing
X Title: @overload outside stubs · Issue #72 · python/typing
Description: PEP 484 says that @overload is only allowed in stubs. But if I have a function like this: def plus1(x): return x + 1 then the most precise type is an overload: def plus1(x: int) -> int def plus1(x: float) -> float def plus1(x: complex) -...
Open Graph Description: PEP 484 says that @overload is only allowed in stubs. But if I have a function like this: def plus1(x): return x + 1 then the most precise type is an overload: def plus1(x: int) -> int def plus1(x:...
X Description: PEP 484 says that @overload is only allowed in stubs. But if I have a function like this: def plus1(x): return x + 1 then the most precise type is an overload: def plus1(x: int) -> int def plus1...
Opengraph URL: https://github.com/python/typing/issues/72
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"@overload outside stubs","articleBody":"PEP 484 says that `@overload` is only allowed in stubs.\n\nBut if I have a function like this:\n\n``` python\n def plus1(x):\n return x + 1\n```\n\nthen the most precise type is an overload:\n\n```\n def plus1(x: int) -> int\n def plus1(x: float) -> float\n def plus1(x: complex) -> complex\n```\n\nThis particular case could, of course, be handled by\n\n``` python\n Number = TypeVar('Number', int, float, complex)\n def f(x: Number) -> Number\n```\n\nBut I can easily construct other examples that can't be solved by type variables.\n\nI don't think that `@overload` requires any additional dispatch machinery in Python (despite what the PEP says) -- it merely describes what the function can do in a more precise way than this:\n\n``` python\n def plus1(x: Union[int,float,complex]) -> Union[int,float,complex]\n```\n","author":{"url":"https://github.com/pludemann","@type":"Person","name":"pludemann"},"datePublished":"2015-03-31T00:53:15Z","url":"https://github.com/python/typing/issues/72"}
| 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:70d476fa-cb17-c313-2bd2-c0b199d9038b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CF1E:390AA2:1E5BF9A:292EBA2:6B0011F7 |
| html-safe-nonce | fd01e8a6c146952f0f412ff2e4bc58708c7292f2183d896094e4df941e0007a2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRjFFOjM5MEFBMjoxRTVCRjlBOjI5MkVCQTI6NkIwMDExRjciLCJ2aXNpdG9yX2lkIjoiNDUwNzA0NTQ5MDAxNzE3ODEwMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c4bf4847cc77a0a971e42fddbf22c6151debce9692d946fd18e7d4c731dde9c1 |
| hovercard-subject-tag | issue:65337224 |
| 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/72/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c34fd0b00c390eabb238e27e2b9a5e05bafcab4f0091959493447850215bc8b9/python/typing/issues/72 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c34fd0b00c390eabb238e27e2b9a5e05bafcab4f0091959493447850215bc8b9/python/typing/issues/72 |
| og:image:alt | PEP 484 says that @overload is only allowed in stubs. But if I have a function like this: def plus1(x): return x + 1 then the most precise type is an overload: def plus1(x: int) -> int def plus1(x:... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | pludemann |
| hostname | github.com |
| expected-hostname | github.com |
| None | cf7ee0062053ad9eb05b6e5de57bd96c2055708bcbada4144946b5ec129cf1d7 |
| 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 | 9cab7de176a56362d2aabcbb4d1e07e846eba8a0 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width