Title: `stubtest` doesn't expand `**kwargs: Unpack[...]` · Issue #21023 · python/mypy · GitHub
Open Graph Title: `stubtest` doesn't expand `**kwargs: Unpack[...]` · Issue #21023 · python/mypy
X Title: `stubtest` doesn't expand `**kwargs: Unpack[...]` · Issue #21023 · python/mypy
Description: Bug Report I am working on a library where some functions have many keyword arguments in common. Therefore, to reduce code duplication, we're taking advantage of the Python typing feature of defining a TypedDict to give a name to that co...
Open Graph Description: Bug Report I am working on a library where some functions have many keyword arguments in common. Therefore, to reduce code duplication, we're taking advantage of the Python typing feature of defini...
X Description: Bug Report I am working on a library where some functions have many keyword arguments in common. Therefore, to reduce code duplication, we're taking advantage of the Python typing feature of de...
Opengraph URL: https://github.com/python/mypy/issues/21023
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`stubtest` doesn't expand `**kwargs: Unpack[...]`","articleBody":"**Bug Report**\n\nI am working on a library where some functions have many keyword arguments in common. Therefore, to reduce code duplication, we're taking advantage of the Python typing feature of defining a `TypedDict` to give a name to that collection of keyword arguments and using `**kwargs: Unpack[...]` in the stubs file to document these functions.\n\nHowever, when these functions are implemented in Rust (using PyO3) and have all the arguments listed separately, `stubtest` reports errors, even though (I believe) these functions are implemented correctly.\n\n**To Reproduce**\n\nI've created a [minimal example project](https://github.com/jbytheway/stubtest-unpack) to demonstrate the problem, but I'll quote the important parts of the implementation here:\n\nThe [stubs file](https://github.com/jbytheway/stubtest-unpack/blob/main/python/stubtest_unpack/_rust.pyi) uses two different approaches to document two functions, which I believe should be equivalent, from a typing perspective:\n\n```python\nclass _Args(TypedDict):\n a: int\n b: int\n\ndef f1(**kwargs: Unpack[_Args]):\n ...\n\ndef f2(*, a: int, b: int):\n ...\n```\n\nThe [Rust implementation](https://github.com/jbytheway/stubtest-unpack/blob/main/src/lib.rs) implements the two identically:\n\n```rust\n #[pyfunction]\n #[pyo3(signature = (*, a, b))]\n fn f1(a: usize, b: usize) -> PyResult\u003cString> {\n Ok((a + b).to_string())\n }\n\n #[pyfunction]\n #[pyo3(signature = (*, a, b))]\n fn f2(a: usize, b: usize) -> PyResult\u003cString> {\n Ok((a + b).to_string())\n }\n```\n\n**Expected Behavior**\n\nNo `stubtest` errors.\n\n**Actual Behavior**\n\n`stubtest` [reports errors](https://github.com/jbytheway/stubtest-unpack/actions/runs/23088801164/job/67069805367) for `f1`, but not for `f2`:\n\n```\nerror: stubtest_unpack._rust.f1 is inconsistent, stub does not have parameter \"a\"\nStub: in file /home/runner/work/stubtest-unpack/stubtest-unpack/.venv/lib/python3.14/site-packages/stubtest_unpack/_rust.pyi:9\ndef (**kwargs: Unpack[TypedDict('stubtest_unpack._rust._Args', {'a': builtins.int, 'b': builtins.int})]) -> Any\nRuntime:\ndef (*, a, b)\n\nerror: stubtest_unpack._rust.f1 is inconsistent, stub does not have parameter \"b\"\nStub: in file /home/runner/work/stubtest-unpack/stubtest-unpack/.venv/lib/python3.14/site-packages/stubtest_unpack/_rust.pyi:9\ndef (**kwargs: Unpack[TypedDict('stubtest_unpack._rust._Args', {'a': builtins.int, 'b': builtins.int})]) -> Any\nRuntime:\ndef (*, a, b)\n\nerror: stubtest_unpack._rust.f1 is inconsistent, runtime does not have **kwargs parameter \"kwargs\"\nStub: in file /home/runner/work/stubtest-unpack/stubtest-unpack/.venv/lib/python3.14/site-packages/stubtest_unpack/_rust.pyi:9\ndef (**kwargs: Unpack[TypedDict('stubtest_unpack._rust._Args', {'a': builtins.int, 'b': builtins.int})]) -> Any\nRuntime:\ndef (*, a, b)\n\nFound 3 errors (checked 1 module)\n```\n\n**Your Environment**\n\nYou can see the full [GitHub CI output](https://github.com/jbytheway/stubtest-unpack/actions/runs/23088801164/job/67069805367) generating the above errors, but here are the highlights:\n\n- Mypy version used: 1.19.1\n- `stubtest` command-line flags: Nothing beyond the module name.","author":{"url":"https://github.com/jbytheway","@type":"Person","name":"jbytheway"},"datePublished":"2026-03-15T13:40:14Z","url":"https://github.com/python/mypy/issues/21023"}
| 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:2a2fbe2a-2f62-74a0-9351-74267156d202 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CBB2:18020:467856:5E3DC0:6B002C8B |
| html-safe-nonce | f9b3f88c72479cf0c29c4da84244a00867d2960a47e1e26212473407f8e3abff |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQkIyOjE4MDIwOjQ2Nzg1Njo1RTNEQzA6NkIwMDJDOEIiLCJ2aXNpdG9yX2lkIjoiNTc5MzYyNjM5ODM1MDM4ODM2MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6dcdfaa079104c684a638a576beaea4db5c2ce6aafc112a92e45bdbdb6530287 |
| hovercard-subject-tag | issue:4078397106 |
| 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/21023/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8f546300044c43a05f38d0b558a79bfcfcd7094eacd8e6776a97ff51ce67e52b/python/mypy/issues/21023 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8f546300044c43a05f38d0b558a79bfcfcd7094eacd8e6776a97ff51ce67e52b/python/mypy/issues/21023 |
| og:image:alt | Bug Report I am working on a library where some functions have many keyword arguments in common. Therefore, to reduce code duplication, we're taking advantage of the Python typing feature of defini... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jbytheway |
| 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