Title: Typing information lost while calling __iter__ · Issue #12446 · python/mypy · GitHub
Open Graph Title: Typing information lost while calling __iter__ · Issue #12446 · python/mypy
X Title: Typing information lost while calling __iter__ · Issue #12446 · python/mypy
Description: With the following example: from typing import Literal dest: Literal["tata", "tutu"] for src in "tata", "tutu": dest = src I'm getting: error: Incompatible types in assignment (expression has type "str", variable has type "Literal['http'...
Open Graph Description: With the following example: from typing import Literal dest: Literal["tata", "tutu"] for src in "tata", "tutu": dest = src I'm getting: error: Incompatible types in assignment (expression has type ...
X Description: With the following example: from typing import Literal dest: Literal["tata", "tutu"] for src in "tata", "tutu": dest = src I'm getting: error: Incompatib...
Opengraph URL: https://github.com/python/mypy/issues/12446
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Typing information lost while calling __iter__","articleBody":"With the following example:\r\n\r\n```python\r\nfrom typing import Literal\r\n\r\ndest: Literal[\"tata\", \"tutu\"]\r\n\r\nfor src in \"tata\", \"tutu\":\r\n dest = src\r\n```\r\n\r\nI'm getting:\r\n\r\n error: Incompatible types in assignment (expression has type \"str\", variable has type \"Literal['http', 'https']\")\r\n\r\nTrying to dig with `reveal_type`:\r\n\r\n```python\r\nt = \"tata\", \"tutu\"\r\nreveal_type(t)\r\nreveal_type(t.__iter__())\r\n```\r\n\r\nI get:\r\n```text\r\ntest.py:2: note: Revealed type is \"Tuple[builtins.str, builtins.str]\"\r\ntest.py:3: note: Revealed type is \"typing.Iterator[builtins.str*]\"\r\n```\r\n\r\nSo it looks OK, but digging with pdb, in `mypy/checker.py:analyze_iterable_item_type()`, after calling:\r\n\r\n iterator = echk.check_method_call_by_name('__iter__', iterable, [], [], expr)[0]\r\n\r\nI see:\r\n\r\n iterable == Tuple[Literal['foo']?, Literal['bar']?]\r\n iterator == typing.Iterator[builtins.str*])\r\n\r\nI think some information is lost here, should iterator get: `typing.Iterator[Literal['foo', 'bar']]` instead? ","author":{"url":"https://github.com/JulienPalard","@type":"Person","name":"JulienPalard"},"datePublished":"2022-03-25T10:14:07Z","url":"https://github.com/python/mypy/issues/12446"}
| 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:e70075ba-516c-f1a2-e08c-1d01c3e07d14 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D81E:251AC0:324351:42FDF4:6B002689 |
| html-safe-nonce | 7043f4d001b52d37ccc223b88020b516eeef12901ecb9ce262a2edefb1066f88 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEODFFOjI1MUFDMDozMjQzNTE6NDJGREY0OjZCMDAyNjg5IiwidmlzaXRvcl9pZCI6Ijc5NzcyOTE1NzY3MDEzNjM4NDkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 752a24c99f113b81474e151048c0ad7fa46c1a5ed8b1d25992ff49f0b8dd123c |
| hovercard-subject-tag | issue:1180597978 |
| 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/12446/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4d1407566648a088b04dd55221193dc29b0685c323da7e3e3b5910cca49086e6/python/mypy/issues/12446 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4d1407566648a088b04dd55221193dc29b0685c323da7e3e3b5910cca49086e6/python/mypy/issues/12446 |
| og:image:alt | With the following example: from typing import Literal dest: Literal["tata", "tutu"] for src in "tata", "tutu": dest = src I'm getting: error: Incompatible types in assignment (expression has type ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JulienPalard |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| 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 | 44c658b24abf00491fb7ae5f56d42c9f38cbeab2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width