Title: Mypy chokes on matching NamedTuple sub-objects in list[Any] member when using said objects: “Argument […] has incompatible type "K"; expected "K"” · Issue #15299 · python/mypy · GitHub
Open Graph Title: Mypy chokes on matching NamedTuple sub-objects in list[Any] member when using said objects: “Argument […] has incompatible type "K"; expected "K"” · Issue #15299 · python/mypy
X Title: Mypy chokes on matching NamedTuple sub-objects in list[Any] member when using said objects: “Argument […] has incompatible type "K"; expected "K"” · Issue #15299 · python/mypy
Description: Bug Report When matching a member-list that is declared to contain Any (I did not check other types here) with [Type() as value] where Type is a NamedTuple, using that value in a seemingly correct way, will state that the type is incompa...
Open Graph Description: Bug Report When matching a member-list that is declared to contain Any (I did not check other types here) with [Type() as value] where Type is a NamedTuple, using that value in a seemingly correct ...
X Description: Bug Report When matching a member-list that is declared to contain Any (I did not check other types here) with [Type() as value] where Type is a NamedTuple, using that value in a seemingly correct ...
Opengraph URL: https://github.com/python/mypy/issues/15299
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Mypy chokes on matching NamedTuple sub-objects in list[Any] member when using said objects: “Argument […] has incompatible type \"K\"; expected \"K\"”","articleBody":"**Bug Report**\r\n\r\nWhen matching a member-list that is declared to contain Any (I did not check other types here) with `[Type() as value]` where `Type` is a `NamedTuple`, using that value in a seemingly correct way, will state that the type is incompatible with the needed type, despite them being the same (mypy prints the same name!).\r\n\r\n**To Reproduce**\r\n\r\n[Playground Link](https://mypy-play.net/?mypy=latest&python=3.11&gist=41ec03557a6a1a7ebe260b4fe6522f06)\r\n\r\n```python\r\nfrom typing import Any, NamedTuple\r\n\r\nclass T(NamedTuple):\r\n t: list[Any]\r\n\r\nclass K(NamedTuple):\r\n k: int\r\n\r\ndef f(t: T) -> None:\r\n d = set[K]()\r\n match t:\r\n case T([K() as k]):\r\n d.add(k)\r\n```\r\n**Expected Behavior**\r\n\r\nI would expect this to be accepted (which is what happens if you run the code and also what pyright says), but in the unlikely event that this is really intentional, I would expect a better error-message than the one given.\r\n\r\n**Actual Behavior**\r\n\r\n```\r\ndemo.py:13: error: Argument 1 to \"add\" of \"set\" has incompatible type \"K\"; expected \"K\" [arg-type]\r\nFound 1 error in 1 file (checked 1 source file)\r\n```\r\n\r\n**Your Environment**\r\n\r\n- Mypy version used: 1.3\r\n- Mypy command-line flags: None or `--strict` (behavior is the same)\r\n- Mypy configuration options from `mypy.ini` (and other config files): None\r\n- Python version used: 3.11","author":{"url":"https://github.com/Fiona-J-W","@type":"Person","name":"Fiona-J-W"},"datePublished":"2023-05-24T14:35:13Z","url":"https://github.com/python/mypy/issues/15299"}
| 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:ef5e9fa3-7250-08ef-6720-ae24210d8fb0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BBE0:2F2EB9:288194A:3542FBB:6B000ADF |
| html-safe-nonce | d83f5a1094ea475f9b98b511970614f6708b52576659047562870e4d65c725c3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQkUwOjJGMkVCOToyODgxOTRBOjM1NDJGQkI6NkIwMDBBREYiLCJ2aXNpdG9yX2lkIjoiMzU3NTY3OTY3NTgwNTk5MzY5NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | eaf99fd34655529c8f9b02118252a9a44f096560286f8ecfa781c29cc64f7669 |
| hovercard-subject-tag | issue:1724149569 |
| 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/15299/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7e291c821f0de1910692df702c51d3138da83e68c7a153cb675d85d0305e2718/python/mypy/issues/15299 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7e291c821f0de1910692df702c51d3138da83e68c7a153cb675d85d0305e2718/python/mypy/issues/15299 |
| og:image:alt | Bug Report When matching a member-list that is declared to contain Any (I did not check other types here) with [Type() as value] where Type is a NamedTuple, using that value in a seemingly correct ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Fiona-J-W |
| 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 | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width