Title: Parameter TypeVar unexpectedly becomes optional when unpacking call results · Issue #20219 · python/mypy · GitHub
Open Graph Title: Parameter TypeVar unexpectedly becomes optional when unpacking call results · Issue #20219 · python/mypy
X Title: Parameter TypeVar unexpectedly becomes optional when unpacking call results · Issue #20219 · python/mypy
Description: Bug Report When calling a generic function mypy unexpectedly introduces optionality in the TypeVar when the result is unpacked and raises an error on a perfectly valid function call: from typing import Iterable def fun[T](values: Iterabl...
Open Graph Description: Bug Report When calling a generic function mypy unexpectedly introduces optionality in the TypeVar when the result is unpacked and raises an error on a perfectly valid function call: from typing im...
X Description: Bug Report When calling a generic function mypy unexpectedly introduces optionality in the TypeVar when the result is unpacked and raises an error on a perfectly valid function call: from typing im...
Opengraph URL: https://github.com/python/mypy/issues/20219
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Parameter TypeVar unexpectedly becomes optional when unpacking call results","articleBody":"**Bug Report**\n\nWhen calling a generic function mypy unexpectedly introduces optionality in the TypeVar when the result is unpacked and raises an error on a perfectly valid function call:\n\n```python\nfrom typing import Iterable\n\n\ndef fun[T](values: Iterable[T], value: list[T]) -> tuple[T | None, T | None]:\n ...\n return None, None\n\n\nvalues: Iterable[int]\nmy_list: list[int]\n\nresult = fun(values, my_list) # works fine\nm, n = result\n\na, b = fun(values, my_list) # raises error in mypy\n```\n\nMypy error:\n```\nmain.py:15: error: Argument 2 to \"fun\" has incompatible type \"list[int]\"; expected \"list[int | None]\" [arg-type]\n```\n\nThis has something to do with the return type of the function being a tuple of optional T's. If the return type is not a union with None or not a tuple, the error disappears.\n\n\n**To reproduce**\n\nHere is playground gist of the example: [gist](https://mypy-play.net/?mypy=master&python=3.14&flags=strict&gist=6b9f22e6fc9b976122326ce980ac9b7c)\n\n\n**Expected Behavior**\n\nIn the example I expect both calls to be approved by mypy. Also, I don't expect unpacking to influence what arguments can given in a function call, at least not in this case.\n\n\n**Actual Behavior**\n\nmypy raises an error on the second call.\n\n\n**Your Environment**\n\nI used mypy playground to confirm this error in various versions:\n\n- Mypy version used: `1.17.1` `1.18.2` `master branch`\n- Mypy command-line flags: none\n- Mypy configuration options from `mypy.ini` (and other config files): none\n- Python version used: `3.12` `3.13` `3.14`\n\n","author":{"url":"https://github.com/exoriente","@type":"Person","name":"exoriente"},"datePublished":"2025-11-11T13:51:44Z","url":"https://github.com/python/mypy/issues/20219"}
| 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:d2c5d005-95c7-2320-4f27-61375a593df3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E818:23D776:F3EFE8:141AAEA:6B000697 |
| html-safe-nonce | 030bf0ffd896a877b830166b68702f1dfde7e1499bb0f4c224d8d9f46adc1930 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFODE4OjIzRDc3NjpGM0VGRTg6MTQxQUFFQTo2QjAwMDY5NyIsInZpc2l0b3JfaWQiOiI4MjgzMjY1MTMyNzY3NzQxNTkxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | a55499d3c059cb6af4168553a3b459721c0fd310d16485f6ebb4dec9b577a272 |
| hovercard-subject-tag | issue:3612420401 |
| 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/20219/issue_layout |
| twitter:image | https://opengraph.githubassets.com/03a9e134df6880a35e8483438635fb7e1598e46d16eddf7a0536779e4beb05c5/python/mypy/issues/20219 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/03a9e134df6880a35e8483438635fb7e1598e46d16eddf7a0536779e4beb05c5/python/mypy/issues/20219 |
| og:image:alt | Bug Report When calling a generic function mypy unexpectedly introduces optionality in the TypeVar when the result is unpacked and raises an error on a perfectly valid function call: from typing im... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | exoriente |
| 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