Title: Narrowing `dict | Literal` does not work in Mypy 1.5.0 · Issue #15860 · python/mypy · GitHub
Open Graph Title: Narrowing `dict | Literal` does not work in Mypy 1.5.0 · Issue #15860 · python/mypy
X Title: Narrowing `dict | Literal` does not work in Mypy 1.5.0 · Issue #15860 · python/mypy
Description: Bug Report When using Mypy 1.5.0, expressions like dict | Literal[""] don't narrow correctly: To Reproduce from typing import Literal x: Literal[""] | dict y: Literal[""] | list if x == "": reveal_type(x) if y == "": reveal_type(y) Mypy ...
Open Graph Description: Bug Report When using Mypy 1.5.0, expressions like dict | Literal[""] don't narrow correctly: To Reproduce from typing import Literal x: Literal[""] | dict y: Literal[""] | list if x == "": reveal_...
X Description: Bug Report When using Mypy 1.5.0, expressions like dict | Literal[""] don't narrow correctly: To Reproduce from typing import Literal x: Literal[""] | dict y: Literal["...
Opengraph URL: https://github.com/python/mypy/issues/15860
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Narrowing `dict | Literal` does not work in Mypy 1.5.0","articleBody":"**Bug Report**\r\n\r\nWhen using Mypy 1.5.0, expressions like `dict | Literal[\"\"]` don't narrow correctly:\r\n\r\n**To Reproduce**\r\n\r\n```python\r\nfrom typing import Literal\r\n\r\nx: Literal[\"\"] | dict\r\ny: Literal[\"\"] | list\r\n\r\nif x == \"\":\r\n reveal_type(x)\r\n\r\nif y == \"\":\r\n reveal_type(y)\r\n```\r\n[Mypy 1.4.1](https://mypy-play.net/?mypy=1.4.1&python=3.11&gist=d692ae5f88611957206e53b3307e3e96)\r\n[Mypy 1.5.0](https://mypy-play.net/?mypy=1.5.0&python=3.11&gist=d692ae5f88611957206e53b3307e3e96)\r\n\r\n**Expected Behavior**\r\n\r\nBoth revealed types should be `Literal[\"\"]`. (As in Mypy 1.4.1.)\r\n\r\n**Actual Behavior**\r\n\r\nMypy 1.5.0 does not narrow the revealed type for `x`. `y` gets narrowed correctly.\r\n\r\n**Your Environment**\r\n\r\nSee Playground links.","author":{"url":"https://github.com/zroug","@type":"Person","name":"zroug"},"datePublished":"2023-08-12T23:56:49Z","url":"https://github.com/python/mypy/issues/15860"}
| 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:2b64f92d-ac0e-c16b-56b1-5451af747b97 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EC98:1A3D7F:26BAA5D:3284CE5:6AFFF8C6 |
| html-safe-nonce | b26f9607732a5dbb1277b9390d59f9877824f4349f310ee45e7e1a73d15fb201 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQzk4OjFBM0Q3RjoyNkJBQTVEOjMyODRDRTU6NkFGRkY4QzYiLCJ2aXNpdG9yX2lkIjoiNzY4MjUyMTI4MzkxMjc5MjI2MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 748d74cd3d60f975a4f52eab4016cfe7d779a0b92b5da7fb6c6d1615ff17c47e |
| hovercard-subject-tag | issue:1848305372 |
| 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/15860/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6666113120bf9dd99507f188cf5464b41dffc5a21071d0459f5691a542bd7c35/python/mypy/issues/15860 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6666113120bf9dd99507f188cf5464b41dffc5a21071d0459f5691a542bd7c35/python/mypy/issues/15860 |
| og:image:alt | Bug Report When using Mypy 1.5.0, expressions like dict | Literal[""] don't narrow correctly: To Reproduce from typing import Literal x: Literal[""] | dict y: Literal[""] | list if x == "": reveal_... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | zroug |
| 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 | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width