Title: Proposal: treat "obvious" return type as annotated · Issue #4409 · python/mypy · GitHub
Open Graph Title: Proposal: treat "obvious" return type as annotated · Issue #4409 · python/mypy
X Title: Proposal: treat "obvious" return type as annotated · Issue #4409 · python/mypy
Description: (Not sure if it should be here or in typing) Consider this function: def f(): return "hello" def g(x): if x: return A(1) else: return A(2) f obviously (without any deep analysis) returns str, and g returns A. Why not use this information...
Open Graph Description: (Not sure if it should be here or in typing) Consider this function: def f(): return "hello" def g(x): if x: return A(1) else: return A(2) f obviously (without any deep analysis) returns str, and g...
X Description: (Not sure if it should be here or in typing) Consider this function: def f(): return "hello" def g(x): if x: return A(1) else: return A(2) f obviously (without any deep analysis) returns ...
Opengraph URL: https://github.com/python/mypy/issues/4409
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Proposal: treat \"obvious\" return type as annotated","articleBody":"(Not sure if it should be here or in typing)\r\n\r\nConsider this function:\r\n```python\r\ndef f():\r\n return \"hello\"\r\ndef g(x):\r\n if x: return A(1)\r\n else: return A(2)\r\n```\r\n\r\n`f` obviously (without any deep analysis) returns `str`, and `g` returns A. Why not use this information? This pattern is very common, and taking advantage of it can help in precise checking and remove clutter (for example ` -> Union[Tuple[int, int, str], Tuple[int, str, bool]]`).\r\n\r\nI propose treating calls to functions whose return expressions consists solely of literals and constructor calls as if they were declared with the returned type (join or union of the return types).","author":{"url":"https://github.com/elazarg","@type":"Person","name":"elazarg"},"datePublished":"2017-12-25T11:40:45Z","url":"https://github.com/python/mypy/issues/4409"}
| 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:c39d4605-8e48-4afd-c5bb-4b18b44929cd |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8D80:5537E:1ADF676:2389454:6B002704 |
| html-safe-nonce | e627e858963d78a9ec2952c04930c1ba7403fcf506cd60cf013457848fe25c0f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RDgwOjU1MzdFOjFBREY2NzY6MjM4OTQ1NDo2QjAwMjcwNCIsInZpc2l0b3JfaWQiOiI1OTI1MzcxNTY1MjE3Njg3MzAwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 98f5abcd6ca1c13c254a3c846b02de04b2371a454f9553ccca6605b75309fc88 |
| hovercard-subject-tag | issue:284439893 |
| 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/4409/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ef650d89eb18288e008b1d04234f1042630d2e409735c76dfa0d0df85196f146/python/mypy/issues/4409 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ef650d89eb18288e008b1d04234f1042630d2e409735c76dfa0d0df85196f146/python/mypy/issues/4409 |
| og:image:alt | (Not sure if it should be here or in typing) Consider this function: def f(): return "hello" def g(x): if x: return A(1) else: return A(2) f obviously (without any deep analysis) returns str, and g... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | elazarg |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| 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 | 44c658b24abf00491fb7ae5f56d42c9f38cbeab2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width