Title: Inconsistent behavior with Literals depending on the amount of elements it contains · Issue #9099 · python/mypy · GitHub
Open Graph Title: Inconsistent behavior with Literals depending on the amount of elements it contains · Issue #9099 · python/mypy
X Title: Inconsistent behavior with Literals depending on the amount of elements it contains · Issue #9099 · python/mypy
Description: Optional static typing for Python. Contribute to python/mypy development by creating an account on GitHub.
Open Graph Description: Optional static typing for Python. Contribute to python/mypy development by creating an account on GitHub.
X Description: Optional static typing for Python. Contribute to python/mypy development by creating an account on GitHub.
Opengraph URL: https://github.com/python/mypy
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inconsistent behavior with Literals depending on the amount of elements it contains","articleBody":"This is an issue I ran into working on #9097. \r\nCode adapted from [this test](https://github.com/python/mypy/blob/master/test-data/unit/check-literal.test#L1469).\r\n\r\nLiterals with one value:\r\n```\r\nfrom typing import List\r\nfrom typing_extensions import Literal\r\n\r\nlit1: Literal[1]\r\nlit2: Literal[2]\r\n\r\narr2 = [lit1, lit2]\r\n\r\nreveal_type(arr2)\r\n```\r\n\r\n```\r\n➜ mypy git:(master) python3 -m mypy leba_misc/test2.py\r\nleba_misc/test2.py:9: note: Revealed type is 'builtins.list[builtins.int*]'\r\n```\r\n\r\nLiterals with multiple values:\r\n```\r\nfrom typing import List\r\nfrom typing_extensions import Literal\r\n\r\nlit1: Literal[1]\r\nlit2: Literal[2, 3]\r\n\r\narr2 = [lit1, lit2]\r\n\r\nreveal_type(arr2)\r\n```\r\n\r\n```\r\n➜ mypy git:(master) python3 -m mypy leba_misc/test2.py\r\nleba_misc/test2.py:9: note: Revealed type is 'builtins.list[Union[Literal[1], Literal[2], Literal[3]]]'\r\n```\r\n\r\nOn `Python 3.7` and `mypy 0.790`.\r\n","author":{"url":"https://github.com/ethan-leba","@type":"Person","name":"ethan-leba"},"datePublished":"2020-07-05T19:33:32Z","url":"https://github.com/python/mypy/issues/9099"}
| 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 | /:user_id/:repository/issues/:id(.:format) |
| route-controller | issues |
| route-action | show |
| fetch-nonce | v2:d54b9bca-eaef-c926-ea0d-a19a05ca8ab7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A600:23FDF9:2273693:2F0321E:6B002FDF |
| html-safe-nonce | 97f05e5c40296f77900e89fd5c753297623113ce06891101a0b35e64e003c7f7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNjAwOjIzRkRGOToyMjczNjkzOjJGMDMyMUU6NkIwMDJGREYiLCJ2aXNpdG9yX2lkIjoiNzMwMTA3NzQwODYyOTY2NTc2MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d99d993502993b15139f7c686521a79e29c7b2dbc25ce289e2124730b5ebff4b |
| hovercard-subject-tag | repository:7053637 |
| 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/python/mypy/issues/9099 |
| twitter:image | https://opengraph.githubassets.com/f79ae5636353a0db17350af0a02700f2e9c3bbcf096f9450bf0c369c77cd1022/python/mypy |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f79ae5636353a0db17350af0a02700f2e9c3bbcf096f9450bf0c369c77cd1022/python/mypy |
| og:image:alt | Optional static typing for Python. Contribute to python/mypy development by creating an account on GitHub. |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| turbo-cache-control | no-cache |
| 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 | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width