Title: Spurious error with `partial` and `TypeVar` · Issue #18953 · python/mypy · GitHub
Open Graph Title: Spurious error with `partial` and `TypeVar` · Issue #18953 · python/mypy
X Title: Spurious error with `partial` and `TypeVar` · Issue #18953 · python/mypy
Description: Bug Report mypy reports a (false) incompatible type error when partial is used on functions with TypeVars. To Reproduce https://mypy-play.net/?mypy=latest&python=3.13&flags=verbose&gist=b65b8dade3556b815d146c8e8ff95427 from typing import...
Open Graph Description: Bug Report mypy reports a (false) incompatible type error when partial is used on functions with TypeVars. To Reproduce https://mypy-play.net/?mypy=latest&python=3.13&flags=verbose&gist=b65b8dade35...
X Description: Bug Report mypy reports a (false) incompatible type error when partial is used on functions with TypeVars. To Reproduce https://mypy-play.net/?mypy=latest&python=3.13&flags=verbose&gist...
Opengraph URL: https://github.com/python/mypy/issues/18953
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Spurious error with `partial` and `TypeVar`","articleBody":"**Bug Report**\n\n`mypy` reports a (false) incompatible type error when `partial` is used on functions with `TypeVar`s.\n\n**To Reproduce**\n\nhttps://mypy-play.net/?mypy=latest&python=3.13&flags=verbose&gist=b65b8dade3556b815d146c8e8ff95427\n\n```python\nfrom typing import TypeVar, overload, Callable\nfrom functools import partial\n\ndef harf(x: Callable[[int], int]) -> None:\n pass\n\ndef func1(a: int, b: str=\"truck\") -> int:\n return a\n\ndef func2[I: (int, str)](a: I, *, b: str=\"truck\") -> I:\n return a\n\nT = TypeVar(\"T\", int, str)\n\ndef func2b(a: T, *, b: str=\"truck\") -> T:\n return a\n\n@overload\ndef func3(a: int, b:str=...) -> int: ...\n\n@overload\ndef func3(a: str, b:str=...) -> str: ...\n\ndef func3(a: int | str, b: str = \"trucl\") -> int | str:\n return a\n\nharf(func1)\nharf(func2)\nharf(func2b)\nharf(func3)\nharf(partial(func1, b=\"harf\"))\nharf(partial(func2, b=\"harf\"))\nharf(partial(func2b, b=\"harf\"))\nharf(partial(func3, b=\"harf\"))\n```\n\n**Expected Behavior**\n\nI do not expect any errors to be reported.\n\n**Actual Behavior**\n\n```text\nmain.py:32: error: Argument 1 to \"harf\" has incompatible type \"partial[I]\"; expected \"Callable[[int], int]\" [arg-type]\nmain.py:32: note: \"partial[I].__call__\" has type \"Callable[[VarArg(Any), KwArg(Any)], I]\"\nmain.py:33: error: Argument 1 to \"harf\" has incompatible type \"partial[T]\"; expected \"Callable[[int], int]\" [arg-type]\nmain.py:33: note: \"partial[T].__call__\" has type \"Callable[[VarArg(Any), KwArg(Any)], T]\"\n```\n\nThose errors are for the two lines where `partial` is used on `func2` and `func2b`, the ones which use a `TypeVar`. No error is reported when used with `func3`, which I believe is an equivalent function, only using `overload` instead of a `TypeVar`.\n\nThis looks like it may be related to https://github.com/python/mypy/issues/15215\n\n**Your Environment**\n\n- Mypy version used: 1.15\n- Mypy command-line flags: None\n- Mypy configuration options from `mypy.ini` (and other config files): None\n- Python version used: 3.13\n\n","author":{"url":"https://github.com/mharding-hpe","@type":"Person","name":"mharding-hpe"},"datePublished":"2025-04-22T20:47:35Z","url":"https://github.com/python/mypy/issues/18953"}
| 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:28699692-ca05-7d8c-73d6-39c51b488ee2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D46E:3AE712:BE2CA9:FF07D9:6B004EA0 |
| html-safe-nonce | c5cb40b6c2710d8156e13b3e37b444fe9e6b42dfc00fb6dabdda48a03b5f07ce |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENDZFOjNBRTcxMjpCRTJDQTk6RkYwN0Q5OjZCMDA0RUEwIiwidmlzaXRvcl9pZCI6IjMyNjI0MDczNzY4NzA4NTQzMDQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 59a8fb51b8b31a4b1f25317410f66082474d41ea15e9b881c0055add04849336 |
| hovercard-subject-tag | issue:3012097463 |
| 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/18953/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3f6144ed2f9a5658ec5bc21f774773ac4514a721479ce156b8679f9f0290b025/python/mypy/issues/18953 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3f6144ed2f9a5658ec5bc21f774773ac4514a721479ce156b8679f9f0290b025/python/mypy/issues/18953 |
| og:image:alt | Bug Report mypy reports a (false) incompatible type error when partial is used on functions with TypeVars. To Reproduce https://mypy-play.net/?mypy=latest&python=3.13&flags=verbose&gist=b65b8dade35... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mharding-hpe |
| hostname | github.com |
| expected-hostname | github.com |
| None | f9517bf360d46638a1e5e7daee7158842fe5ef43c9000afa0e127564a7c2f39b |
| 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 | b27c5dde30676028abd5c5fc53ce5c9b625f8281 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width