Title: Variadic tuple unpacking requires a star target -- why? · Issue #17282 · python/mypy · GitHub
Open Graph Title: Variadic tuple unpacking requires a star target -- why? · Issue #17282 · python/mypy
X Title: Variadic tuple unpacking requires a star target -- why? · Issue #17282 · python/mypy
Description: Bug Report When attempting to unpack a tuple that uses Unpack, if you don't use a star target to capture the variadic tuple as a list, you get the error Variadic tuple unpacking requires a star target. This is overly strict and prescript...
Open Graph Description: Bug Report When attempting to unpack a tuple that uses Unpack, if you don't use a star target to capture the variadic tuple as a list, you get the error Variadic tuple unpacking requires a star tar...
X Description: Bug Report When attempting to unpack a tuple that uses Unpack, if you don't use a star target to capture the variadic tuple as a list, you get the error Variadic tuple unpacking requires a star...
Opengraph URL: https://github.com/python/mypy/issues/17282
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Variadic tuple unpacking requires a star target -- why?","articleBody":"**Bug Report**\r\n\r\nWhen attempting to unpack a `tuple` that uses `Unpack`, if you don't use a star target to capture the variadic `tuple` as a `list`, you get the error `Variadic tuple unpacking requires a star target`.\r\n\r\nThis is overly strict and prescriptivist and is not even applied consistently between similar type concepts within `mypy`.\r\n\r\n1. You definitely can do this if the lengths check out.\r\n2. `pyright` doesn't raise an error like this. You are simply on your own for length checking the unpacking of indeterminate length `tuple`s, just like you are for `list`, another indeterminate length unpackable sequence.\r\n3. In fact, this is also how `mypy` treats unpacking `list`. It doesn't raise an error if you don't use a star target.\r\n4. I have a real use case where I want to do exactly this. I lay out my use case in this bug report to `pyright`: https://github.com/microsoft/pyright/issues/7987\r\n\r\n**To Reproduce**\r\n\r\n```python\r\nfrom typing import Tuple\r\n\r\nfrom typing_extensions import Unpack\r\n\r\n\r\ndef foo() -> Tuple[int, Unpack[Tuple[str, ...]]]:\r\n return 1, \"bar\", \"baz\"\r\n\r\na, b, c = foo() # error: Variadic tuple unpacking requires a star target [misc]\r\n\r\nd, e, f = [1, \"bar\", \"baz\"] # OK\r\n\r\n```\r\n\r\nGist URL: https://gist.github.com/mypy-play/4014976ca069e54b5c1fe86a45353f58\r\nPlayground URL: https://mypy-play.net/?mypy=master&python=3.12&gist=4014976ca069e54b5c1fe86a45353f58\r\n\r\n**Expected Behavior**\r\n\r\nNo errors in the above example. `a`'s type should be revealed to be `int`, and `b` and `c`'s types should be revealed to be `str`.\r\n\r\n**Actual Behavior**\r\n\r\nAn error, and `a`, `b`, and `c` are all revealed to be `Any`.\r\n","author":{"url":"https://github.com/ringohoffman","@type":"Person","name":"ringohoffman"},"datePublished":"2024-05-24T07:06:22Z","url":"https://github.com/python/mypy/issues/17282"}
| 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:2b4b8a06-ec47-4303-68ca-f063937f2c25 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 92AA:3204C8:2EF784E:3DFD095:6B002560 |
| html-safe-nonce | 2415499124f13215653462826b09416993de446ddb98b80f085fbbdc9859858c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MkFBOjMyMDRDODoyRUY3ODRFOjNERkQwOTU6NkIwMDI1NjAiLCJ2aXNpdG9yX2lkIjoiNTUzNDA3NTcyMjE1MjI4OTYzMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 2bf37071447380ffe888cc33509ed477c2989a98a538e0c2ec2216ed9e318c1d |
| hovercard-subject-tag | issue:2314589648 |
| 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/17282/issue_layout |
| twitter:image | https://opengraph.githubassets.com/22812c8feef088688ac4d8ffd292cb6ef9d27469907fefea62b841d113227f90/python/mypy/issues/17282 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/22812c8feef088688ac4d8ffd292cb6ef9d27469907fefea62b841d113227f90/python/mypy/issues/17282 |
| og:image:alt | Bug Report When attempting to unpack a tuple that uses Unpack, if you don't use a star target to capture the variadic tuple as a list, you get the error Variadic tuple unpacking requires a star tar... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ringohoffman |
| 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