Title: Is it possible to overload depending on the presence of an argument? · Issue #248 · python/typing · GitHub
Open Graph Title: Is it possible to overload depending on the presence of an argument? · Issue #248 · python/typing
X Title: Is it possible to overload depending on the presence of an argument? · Issue #248 · python/typing
Description: I'm not sure if this is an issue, a feature request, or a question... While trying to write typesheds for numpy I found this (simplified) situation: I have a method with the following signature T = TypeVar('T') def foo(self, arg1: int=.....
Open Graph Description: I'm not sure if this is an issue, a feature request, or a question... While trying to write typesheds for numpy I found this (simplified) situation: I have a method with the following signature T =...
X Description: I'm not sure if this is an issue, a feature request, or a question... While trying to write typesheds for numpy I found this (simplified) situation: I have a method with the following signature...
Opengraph URL: https://github.com/python/typing/issues/248
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Is it possible to overload depending on the presence of an argument?","articleBody":"I'm not sure if this is an issue, a feature request, or a question...\n\nWhile trying to write typesheds for numpy I found this (simplified) situation:\n\nI have a method with the following signature\n\n``` python\nT = TypeVar('T')\ndef foo(self, arg1: int=..., arg2: int=..., *, out: T=None):\n```\n\nThe function returns a `bool` when the `out` argument is not present (so `foo()`, `foo(x, y)`, `foo(arg2=x)` all are boolean values).\n\nThe function returns a `T` when the `out` argument is present (so `foo(out=\"hello\")`, `foo(x, y, out=\"hello\")`, `foo(out=\"hello\", arg2=x)` all are string values).\n\nI was trying to describe that as an overload (and restricting to keyword only args to avoid mistakes):\n\n``` python\nfrom typing import TypeVar, overload\n\nT = TypeVar('T')\n\nclass C:\n @overload\n def foo(self, *, arg1: int=0, arg2: int=0) -> bool: ...\n @overload\n def foo(self, *, arg1: int=0, arg2: int=0, out:T=None) -> T: ...\n\nreveal_type(C().foo())\nreveal_type(C().foo(out=\"hello\"))\n```\n\nbut the revealed_type for the result of the first call is \"Any\". I don't think my definition should be ok (my overloaded signatures are ambiguous), but an Any there is certainly unexpected there. Also, I'm not sure what would be (if possible) the way to express this situation with mypy's type system\n","author":{"url":"https://github.com/dmoisset","@type":"Person","name":"dmoisset"},"datePublished":"2016-07-18T20:42:52Z","url":"https://github.com/python/typing/issues/248"}
| 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:a3f62762-38ab-1276-98db-cc9f4432cb45 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8A72:CF959:2AD6909:3822DD3:6B000A0C |
| html-safe-nonce | ca0c07f3ff9729a1dd4624e736699e5ef228ea3c6767541d6261dd3bf76931f4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QTcyOkNGOTU5OjJBRDY5MDk6MzgyMkREMzo2QjAwMEEwQyIsInZpc2l0b3JfaWQiOiI5MTU5NTc5MTQyODA1NTIyOTU2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 4e299df61f98f715cb7b228bca9f4f7b6c9f7b6e789dd5e50dd12e9635c2cc3d |
| hovercard-subject-tag | issue:166188716 |
| 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/248/issue_layout |
| twitter:image | https://opengraph.githubassets.com/edbfc232c7bab18fef546ef06f42bff26888ce96cc9c3d98f1997945213259aa/python/typing/issues/248 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/edbfc232c7bab18fef546ef06f42bff26888ce96cc9c3d98f1997945213259aa/python/typing/issues/248 |
| og:image:alt | I'm not sure if this is an issue, a feature request, or a question... While trying to write typesheds for numpy I found this (simplified) situation: I have a method with the following signature T =... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dmoisset |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0a0d8686a27478df474dd7415776a7a080cde8838b3cd92ea7601187572e5729 |
| 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 | 16a11879678aaf97e2a42c33ee70830aa084fa37 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width