Title: tagged union of unions · Issue #9308 · python/mypy · GitHub
Open Graph Title: tagged union of unions · Issue #9308 · python/mypy
X Title: tagged union of unions · Issue #9308 · python/mypy
Description: Report Type: Bug Example: https://mypy-play.net/?mypy=latest&python=3.8&gist=529e99849ebe65749d8568b743f21050 I saw #8925. It could be seen as a duplicate, not sure about it, but this one looks slightly different and more general as the ...
Open Graph Description: Report Type: Bug Example: https://mypy-play.net/?mypy=latest&python=3.8&gist=529e99849ebe65749d8568b743f21050 I saw #8925. It could be seen as a duplicate, not sure about it, but this one looks sli...
X Description: Report Type: Bug Example: https://mypy-play.net/?mypy=latest&python=3.8&gist=529e99849ebe65749d8568b743f21050 I saw #8925. It could be seen as a duplicate, not sure about it, but this one l...
Opengraph URL: https://github.com/python/mypy/issues/9308
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"tagged union of unions","articleBody":"**Report Type:** Bug\r\n\r\n**Example:** https://mypy-play.net/?mypy=latest&python=3.8&gist=529e99849ebe65749d8568b743f21050\r\n\r\nI saw https://github.com/python/mypy/issues/8925.\r\n\r\nIt could be seen as a duplicate, not sure about it, but this one looks slightly different and more general as the one linked above, it's not only about `None` in unions but more about unions of unions where mypy has difficulties to narrow the correct TypedDict\r\n\r\n```python\r\nfrom typing import Literal, TypedDict, Union\r\n\r\nclass NewJobEvent(TypedDict):\r\n tag: Literal[\"new-job\"]\r\n job_name: str\r\n config_file_path: str\r\n\r\nclass CancelJobEvent(TypedDict):\r\n tag: Literal[\"cancel-job\"]\r\n job_id: int\r\n\r\nclass AnotherOne(TypedDict):\r\n tag: Literal[\"another\"]\r\n another: int\r\n\r\n\r\nEvent = Union[NewJobEvent, CancelJobEvent]\r\n\r\nAnotherUnionEvent = Union[Event, AnotherOne]\r\n\r\nevent: Event\r\nif event[\"tag\"] == \"new-job\":\r\n reveal_type(event)\r\nelse:\r\n reveal_type(event)\r\n \r\n\r\nanother_union_event: AnotherUnionEvent\r\nif another_union_event[\"tag\"] == \"new-job\":\r\n reveal_type(another_union_event)\r\nelse:\r\n reveal_type(another_union_event)\r\n```\r\n\r\n* What is the actual behavior/output?\r\n```\r\nmain.py:23: note: Revealed type is 'TypedDict('main.NewJobEvent', {'tag': Literal['new-job'], 'job_name': builtins.str, 'config_file_path': builtins.str})'\r\nmain.py:25: note: Revealed type is 'TypedDict('main.CancelJobEvent', {'tag': Literal['cancel-job'], 'job_id': builtins.int})'\r\nmain.py:30: note: Revealed type is 'Union[TypedDict('main.NewJobEvent', {'tag': Literal['new-job'], 'job_name': builtins.str, 'config_file_path': builtins.str}), TypedDict('main.CancelJobEvent', {'tag': Literal['cancel-job'], 'job_id': builtins.int}), TypedDict('main.AnotherOne', {'tag': Literal['another'], 'another': builtins.int})]'\r\nmain.py:32: note: Revealed type is 'Union[TypedDict('main.NewJobEvent', {'tag': Literal['new-job'], 'job_name': builtins.str, 'config_file_path': builtins.str}), TypedDict('main.CancelJobEvent', {'tag': Literal['cancel-job'], 'job_id': builtins.int}), TypedDict('main.AnotherOne', {'tag': Literal['another'], 'another': builtins.int})]'\r\n```\r\n\r\n* What is the behavior/output you expect?\r\nI would expect the union of union to be narrowed\r\n\r\n* What are the versions of mypy and Python you are using?\r\nv0.782\r\n\r\n* Do you see the same issue after installing mypy from Git master?\r\nyes\r\n\r\n* What are the mypy flags you are using? (For example --strict-optional)\r\n```\r\n[mypy]\r\ndisallow_untyped_defs = True\r\nignore_missing_imports = True\r\n```","author":{"url":"https://github.com/euri10","@type":"Person","name":"euri10"},"datePublished":"2020-08-14T13:28:01Z","url":"https://github.com/python/mypy/issues/9308"}
| 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:2dccec83-99f0-0f19-1140-9dc44543fc05 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A1B0:D33AC:E6CBC3:1350C0A:6B0057F6 |
| html-safe-nonce | 65315ed96dfcbdab6673bd096defbc7f34f62ede5be2b6b61c4b285225cc282a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMUIwOkQzM0FDOkU2Q0JDMzoxMzUwQzBBOjZCMDA1N0Y2IiwidmlzaXRvcl9pZCI6IjcwMzYwOTE3MDkwMTY1Mjg4ODYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | abe69095230ce0a076b40008369aba26471e8eb97a52ac63415a1c823e595fca |
| hovercard-subject-tag | issue:679156971 |
| 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/9308/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8adcb572c3f2da1536a73198d5985149b063f1b6b6e2280198ac37a0663cc048/python/mypy/issues/9308 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8adcb572c3f2da1536a73198d5985149b063f1b6b6e2280198ac37a0663cc048/python/mypy/issues/9308 |
| og:image:alt | Report Type: Bug Example: https://mypy-play.net/?mypy=latest&python=3.8&gist=529e99849ebe65749d8568b743f21050 I saw #8925. It could be seen as a duplicate, not sure about it, but this one looks sli... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | euri10 |
| hostname | github.com |
| expected-hostname | github.com |
| None | f420f4996e6b1ff1ccd6d7683f8134f4b5f0f8a50124c210dbfe7490e5644abb |
| 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 | 26e00df917aba0f128135dc073ea0c5e33a70d40 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width