Title: Conditional expression with branches of type None and T should be Optional[T], not object · Issue #1820 · python/mypy · GitHub
Open Graph Title: Conditional expression with branches of type None and T should be Optional[T], not object · Issue #1820 · python/mypy
X Title: Conditional expression with branches of type None and T should be Optional[T], not object · Issue #1820 · python/mypy
Description: Consider: def f(flag; bool) -> Optional[int]: a = (None if flag else 0) return a When run with --strict-optional I get the error error: Incompatible return value type (got "object", expected "Optional[int]") It looks like the unification...
Open Graph Description: Consider: def f(flag; bool) -> Optional[int]: a = (None if flag else 0) return a When run with --strict-optional I get the error error: Incompatible return value type (got "object", expected "Optio...
X Description: Consider: def f(flag; bool) -> Optional[int]: a = (None if flag else 0) return a When run with --strict-optional I get the error error: Incompatible return value type (got "object", ex...
Opengraph URL: https://github.com/python/mypy/issues/1820
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Conditional expression with branches of type None and T should be Optional[T], not object","articleBody":"Consider:\n\n``` python\ndef f(flag; bool) -> Optional[int]:\n a = (None if flag else 0)\n return a\n```\n\nWhen run with `--strict-optional` I get the error\n\n```\nerror: Incompatible return value type (got \"object\", expected \"Optional[int]\")\n```\n\nIt looks like the unification code is not understanding what's going on and falling back on `object`.\n","author":{"url":"https://github.com/gvanrossum","@type":"Person","name":"gvanrossum"},"datePublished":"2016-07-07T20:50:08Z","url":"https://github.com/python/mypy/issues/1820"}
| 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:994f7976-716a-efe2-da6d-dd200a06d031 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8DBA:CEC0A:293324E:36230C6:6B000C63 |
| html-safe-nonce | ec2fa9345f0d778c347768b21ddfff888c08bf645376a86f53d7ce0e2992b505 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4REJBOkNFQzBBOjI5MzMyNEU6MzYyMzBDNjo2QjAwMEM2MyIsInZpc2l0b3JfaWQiOiIzOTE4MDMyOTM2MzA5MzYxNzYzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | ebff2599bd10dc5efa40f12087fda8036bc7da11afc17dbb35568231d1781626 |
| hovercard-subject-tag | issue:164404144 |
| 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/1820/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d72ce2d345f2642aca633c537c5a6a96e21205da679761a54dc4c4a9c32ba00c/python/mypy/issues/1820 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d72ce2d345f2642aca633c537c5a6a96e21205da679761a54dc4c4a9c32ba00c/python/mypy/issues/1820 |
| og:image:alt | Consider: def f(flag; bool) -> Optional[int]: a = (None if flag else 0) return a When run with --strict-optional I get the error error: Incompatible return value type (got "object", expected "Optio... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gvanrossum |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0a0d8686a27478df474dd7415776a7a080cde8838b3cd92ea7601187572e5729 |
| 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 | 16a11879678aaf97e2a42c33ee70830aa084fa37 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width