Title: Optional generic not accepted with `--strict-optional` · Issue #2678 · python/mypy · GitHub
Open Graph Title: Optional generic not accepted with `--strict-optional` · Issue #2678 · python/mypy
X Title: Optional generic not accepted with `--strict-optional` · Issue #2678 · python/mypy
Description: When running with --strict-optional, mypy complains about the last statement here. However, this seems like it should work, both because it does work when --strict-optional is left out, and because the revealed type looks like it should ...
Open Graph Description: When running with --strict-optional, mypy complains about the last statement here. However, this seems like it should work, both because it does work when --strict-optional is left out, and because...
X Description: When running with --strict-optional, mypy complains about the last statement here. However, this seems like it should work, both because it does work when --strict-optional is left out, and because...
Opengraph URL: https://github.com/python/mypy/issues/2678
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Optional generic not accepted with `--strict-optional`","articleBody":"When running with `--strict-optional`, mypy complains about the last statement here. However, this seems like it should work, both because it does work when `--strict-optional` is left out, and because the revealed type looks like it should match.\r\n\r\n```python\r\nfrom typing import Optional, Type, TypeVar\r\n\r\n\r\nclass BaseThing: pass\r\nclass ChildThing(BaseThing): pass\r\n\r\n\r\nThingClass = TypeVar(\"ThingClass\", bound=BaseThing)\r\n\r\n\r\ndef get_thing(thing_class: Type[ThingClass]) -> Optional[ThingClass]:\r\n \"\"\" Get the thing with the given class. Stub implementation. \"\"\"\r\n return None\r\n\r\nthing = None # type: Optional[ChildThing]\r\n\r\n# Fails, complaining about `Type argument 1 of \"get_thing\" has incompatible value \"Optional[ChildThing]\"`\r\nthing = get_thing(ChildThing)\r\n\r\n# Revealed type is `Union[scratch_1.ChildThing*, builtins.None]`, which seems like it should \r\n# match Optional[ChildThing].\r\nreveal_type(get_thing(ChildThing))\r\n```","author":{"url":"https://github.com/FuegoFro","@type":"Person","name":"FuegoFro"},"datePublished":"2017-01-11T18:03:16Z","url":"https://github.com/python/mypy/issues/2678"}
| 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:6e2d1b8c-eb0d-580d-60eb-770f11801e25 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A9E4:29A20E:187E3CD:20F3B7E:6AFFF16F |
| html-safe-nonce | 28d593ab0b91580b6a1ecc21f0df10e833d309aa87aaade9c86a572b51a86662 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOUU0OjI5QTIwRToxODdFM0NEOjIwRjNCN0U6NkFGRkYxNkYiLCJ2aXNpdG9yX2lkIjoiMTQzNzc1NDQzODg2ODUyOTUxOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 42739007a847f728b688503a8fe1f83882aa07bb37a9230187d1102cbd961b0d |
| hovercard-subject-tag | issue:200165537 |
| 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/2678/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9b59de8078564ae7c3a941e60d24fc5535e225f50ed94ba69b96e5042496ffc9/python/mypy/issues/2678 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9b59de8078564ae7c3a941e60d24fc5535e225f50ed94ba69b96e5042496ffc9/python/mypy/issues/2678 |
| og:image:alt | When running with --strict-optional, mypy complains about the last statement here. However, this seems like it should work, both because it does work when --strict-optional is left out, and because... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | FuegoFro |
| 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