Title: Looping through literals not typed correctly · Issue #9230 · python/mypy · GitHub
Open Graph Title: Looping through literals not typed correctly · Issue #9230 · python/mypy
X Title: Looping through literals not typed correctly · Issue #9230 · python/mypy
Description: Iterating through a fixed Tuple of strings ("foo", "bar") makes the loop variable a str instead of Union[Literal["foo"], Literal["bar"]]. This makes it difficult to loop through indices of a TypedDict.´ https://mypy-play.net/?mypy=latest...
Open Graph Description: Iterating through a fixed Tuple of strings ("foo", "bar") makes the loop variable a str instead of Union[Literal["foo"], Literal["bar"]]. This makes it difficult to loop through indices of a TypedD...
X Description: Iterating through a fixed Tuple of strings ("foo", "bar") makes the loop variable a str instead of Union[Literal["foo"], Literal["bar"]]. This makes it diffi...
Opengraph URL: https://github.com/python/mypy/issues/9230
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Looping through literals not typed correctly","articleBody":"Iterating through a fixed `Tuple` of strings `(\"foo\", \"bar\")` makes the loop variable a `str` instead of `Union[Literal[\"foo\"], Literal[\"bar\"]]`. This makes it difficult to loop through indices of a `TypedDict`.´\r\n\r\nhttps://mypy-play.net/?mypy=latest&python=3.8&gist=17fe6a875f727a01fe3a5c6dca13dba2\r\n```python\r\nfrom typing import TypedDict\r\n\r\nclass FooDict(TypedDict):\r\n foo: int\r\n bar: int\r\n \r\nfoo = FooDict(foo=3, bar=3)\r\n\r\nprint(foo[\"foo\"]) # Works\r\nprint(foo[\"bar\"]) # Works\r\nreveal_type((\"foo\", \"bar\")) # Revealed type is 'Tuple[Literal['foo']?, Literal['bar']?]'\r\n\r\nfor key in (\"foo\", \"bar\"):\r\n reveal_type(key) # Revealed type is 'builtins.str'\r\n print(foo[key]) # TypedDict key must be a string literal; expected one of ('foo', 'bar')\r\n```","author":{"url":"https://github.com/rggjan","@type":"Person","name":"rggjan"},"datePublished":"2020-07-29T06:48:56Z","url":"https://github.com/python/mypy/issues/9230"}
| 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:dde93083-6fd1-87cd-a87c-9e342fc4a0df |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B91C:1A3D7F:3112A84:40E88F5:6B002971 |
| html-safe-nonce | 33eb87a1d9e76a48e927a2a99d6a5d449d6d9830f6fc9ab2a0835c4cf9a7f3e5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOTFDOjFBM0Q3RjozMTEyQTg0OjQwRTg4RjU6NkIwMDI5NzEiLCJ2aXNpdG9yX2lkIjoiMjA1MTYwOTQwNTUzODk2OTk2OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f26204ac899486237b39788dc68f9e4ee5baeb10a36ab485a8531a45444a2629 |
| hovercard-subject-tag | issue:667597103 |
| 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/9230/issue_layout |
| twitter:image | https://opengraph.githubassets.com/fb53b5a944ac4eb0d6dd3fed88230a158e8e0f93d098b44a919813b47ba409d8/python/mypy/issues/9230 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/fb53b5a944ac4eb0d6dd3fed88230a158e8e0f93d098b44a919813b47ba409d8/python/mypy/issues/9230 |
| og:image:alt | Iterating through a fixed Tuple of strings ("foo", "bar") makes the loop variable a str instead of Union[Literal["foo"], Literal["bar"]]. This makes it difficult to loop through indices of a TypedD... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rggjan |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| 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 | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width