Title: Problem with `str` being treated as `Sequence[str]` · Issue #5090 · python/mypy · GitHub
Open Graph Title: Problem with `str` being treated as `Sequence[str]` · Issue #5090 · python/mypy
X Title: Problem with `str` being treated as `Sequence[str]` · Issue #5090 · python/mypy
Description: Are you reporting a bug, or opening a feature request? I think it's a bug or very unexpected behavior at least. Related issues I found: #1965, #4334. Code d = {'k1': 'qwe', 'k2': []} reveal_type(d) value: str = d['k1'] Actual Output $ my...
Open Graph Description: Are you reporting a bug, or opening a feature request? I think it's a bug or very unexpected behavior at least. Related issues I found: #1965, #4334. Code d = {'k1': 'qwe', 'k2': []} reveal_type(d)...
X Description: Are you reporting a bug, or opening a feature request? I think it's a bug or very unexpected behavior at least. Related issues I found: #1965, #4334. Code d = {'k1': 'qwe', '...
Opengraph URL: https://github.com/python/mypy/issues/5090
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Problem with `str` being treated as `Sequence[str]`","articleBody":"**Are you reporting a bug, or opening a feature request?**\r\n\r\nI think it's a bug or very unexpected behavior at least. Related issues I found: #1965, #4334. \r\n\r\n**Code**\r\n```python \r\nd = {'k1': 'qwe', 'k2': []}\r\nreveal_type(d)\r\nvalue: str = d['k1']\r\n```\r\n\r\n**Actual Output**\r\n```bash\r\n$ mypy file.py\r\nfile.py:2: error: Revealed type is 'builtins.dict[builtins.str*, typing.Sequence*[builtins.str]]'\r\nfile.py:3: error: Incompatible types in assignment (expression has type \"Sequence[str]\", variable has type \"str\")\r\n```\r\n\r\nSo, as far as I understand, mypy tried to find the strictest type for values of `d`, which is `Sequence[str]` in this case. In Python, string is a Sequence of (sub)strings (`s[0] == s[0][0] == s[0][0][0]`), also list is a Sequence, so this is understandable. Unfortunately, the rule that string is a sequence of (sub)strings does not work in case of `value: str = d['k1']`.\r\n\r\n**Expected output**\r\nTo get rid of the error I need to manually give more general type: `d: Dict[str, Any]`, so this is not such a big problem. Having said that, expected behavior would be: _No \"Incompatible types in assignment\" error for the given code_.\r\n\r\n**Versions**\r\nPython 3.6.5\r\nmypy==0.600","author":{"url":"https://github.com/pawelswiecki","@type":"Person","name":"pawelswiecki"},"datePublished":"2018-05-21T14:37:39Z","url":"https://github.com/python/mypy/issues/5090"}
| 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:a1a7b4e8-df79-a18a-743f-c7bbd6d437da |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AA34:302FC:72791A:98AD68:6B0038BD |
| html-safe-nonce | 8b3c697f1b318b22a6561377272d930ee048ef980caf6abb5fccd31e08cad649 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQTM0OjMwMkZDOjcyNzkxQTo5OEFENjg6NkIwMDM4QkQiLCJ2aXNpdG9yX2lkIjoiODIwNzU3ODYwMDYwMjM1MTgwNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 5b20b9269f811c17559e2989fc96a5f5256871f40878fd244bcf03b1bfc30bbc |
| hovercard-subject-tag | issue:324940296 |
| 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/5090/issue_layout |
| twitter:image | https://opengraph.githubassets.com/141553eb5591b5fe4c0edbf7461d104771e8945c1167c5b412adadd269b0be70/python/mypy/issues/5090 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/141553eb5591b5fe4c0edbf7461d104771e8945c1167c5b412adadd269b0be70/python/mypy/issues/5090 |
| og:image:alt | Are you reporting a bug, or opening a feature request? I think it's a bug or very unexpected behavior at least. Related issues I found: #1965, #4334. Code d = {'k1': 'qwe', 'k2': []} reveal_type(d)... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | pawelswiecki |
| 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