Title: [regression] Function wrapped with `ParamSpec[Concatenate[]]` is not compatible with `Callable[..., Any]` · Issue #16247 · python/mypy · GitHub
Open Graph Title: [regression] Function wrapped with `ParamSpec[Concatenate[]]` is not compatible with `Callable[..., Any]` · Issue #16247 · python/mypy
X Title: [regression] Function wrapped with `ParamSpec[Concatenate[]]` is not compatible with `Callable[..., Any]` · Issue #16247 · python/mypy
Description: Bug Report I have a decorator-like function that takes a Callable[Concatenate[...], ...] as an argument and returns a wrapped callable with the same signature. After upgrading from mypy 1.5.1 to 1.6.0, a wrapped function is no longer con...
Open Graph Description: Bug Report I have a decorator-like function that takes a Callable[Concatenate[...], ...] as an argument and returns a wrapped callable with the same signature. After upgrading from mypy 1.5.1 to 1....
X Description: Bug Report I have a decorator-like function that takes a Callable[Concatenate[...], ...] as an argument and returns a wrapped callable with the same signature. After upgrading from mypy 1.5.1 to 1....
Opengraph URL: https://github.com/python/mypy/issues/16247
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[regression] Function wrapped with `ParamSpec[Concatenate[]]` is not compatible with `Callable[..., Any]`","articleBody":"**Bug Report**\r\n\r\nI have a decorator-like function that takes a `Callable[Concatenate[...], ...]` as an argument and returns a wrapped callable with the same signature.\r\n\r\nAfter upgrading from mypy 1.5.1 to 1.6.0, a wrapped function is no longer considered compatble when it should be. My understanding is that `Callable[..., Any]` should be compatible with **every possible callable**, but it fails with:\r\n\r\n> main.py:24: error: Argument 1 to \"wrap_func\" has incompatible type \"Callable[[str], bool]\"; expected \"Callable[[str, VarArg(Any), KwArg(Any)], Any]\" [arg-type]\r\n\r\n**To Reproduce**\r\n\r\n* Mypy 1.6.0 ❌ https://mypy-play.net/?mypy=1.6.0&python=3.11&gist=6af0ba1e82c661584eee28e19f02880b\r\n* Mypy 1.5.1 ✅ https://mypy-play.net/?mypy=1.5.1&python=3.11&gist=6af0ba1e82c661584eee28e19f02880b\r\n\r\n```python\r\nfrom typing import Concatenate, ParamSpec, TypeVar, reveal_type, Any, Callable\r\n\r\nP = ParamSpec(\"P\")\r\nRT = TypeVar(\"RT\")\r\n\r\n\r\ndef wrap_func(wrapped_func: Callable[Concatenate[str, P], RT]) -> Callable[Concatenate[str, P], RT]:\r\n return wrapped_func\r\n\r\n\r\ndef func(value: str, /) -> bool:\r\n return bool(value)\r\n\r\n\r\nwrapped0 = wrap_func(func)\r\nreveal_type(wrapped0) # N: Revealed type is \"def (builtins.str) -> builtins.bool\"\r\n\r\nwrapped1: Callable[[str], Any] = wrap_func(func) # ✅\r\nwrapped2: Callable[[str], object] = wrap_func(func) # ✅\r\nwrapped3: Callable[[str], int] = wrap_func(func) # ✅\r\nwrapped4: Callable[[str], bool] = wrap_func(func) # ✅\r\n\r\nwrapped5: Callable = wrap_func(func) # ❌ expected \"Callable[[str, VarArg(Any), KwArg(Any)], Any]\"\r\nwrapped6: Callable[..., Any] = wrap_func(func) # ❌ expected \"Callable[[str, VarArg(Any), KwArg(Any)], Any]\"\r\nwrapped7: Callable[..., object] = wrap_func(func) # ❌ expected \"Callable[[str, VarArg(Any), KwArg(Any)], bool]\"\r\nwrapped8: Callable[..., int] = wrap_func(func) # ❌ expected \"Callable[[str, VarArg(Any), KwArg(Any)], int]\"\r\nwrapped9: Callable[..., bool] = wrap_func(func) # ❌ expected \"Callable[[str, VarArg(Any), KwArg(Any)], bool]\"\r\n```\r\n\r\n**Actual Behavior**\r\n\r\n```\r\nmain.py:24: error: Argument 1 to \"wrap_func\" has incompatible type \"Callable[[str], bool]\"; expected \"Callable[[str, VarArg(Any), KwArg(Any)], Any]\" [arg-type]\r\nmain.py:25: error: Argument 1 to \"wrap_func\" has incompatible type \"Callable[[str], bool]\"; expected \"Callable[[str, VarArg(Any), KwArg(Any)], Any]\" [arg-type]\r\nmain.py:26: error: Argument 1 to \"wrap_func\" has incompatible type \"Callable[[str], bool]\"; expected \"Callable[[str, VarArg(Any), KwArg(Any)], bool]\" [arg-type]\r\nmain.py:27: error: Argument 1 to \"wrap_func\" has incompatible type \"Callable[[str], bool]\"; expected \"Callable[[str, VarArg(Any), KwArg(Any)], int]\" [arg-type]\r\nmain.py:28: error: Argument 1 to \"wrap_func\" has incompatible type \"Callable[[str], bool]\"; expected \"Callable[[str, VarArg(Any), KwArg(Any)], bool]\" [arg-type]\r\n```\r\n\r\n**Your Environment**\r\n\r\n- Mypy version used: 1.6.0\r\n- Mypy command-line flags: -\r\n- Python version used: 3.11.6\r\n","author":{"url":"https://github.com/intgr","@type":"Person","name":"intgr"},"datePublished":"2023-10-11T12:52:34Z","url":"https://github.com/python/mypy/issues/16247"}
| 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:658ed522-8f89-19b9-c6d4-fdbcb8bc3d24 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D4F6:354B:E1F13D:127FB0C:6AFFF191 |
| html-safe-nonce | b8326fd2391e27a5f43414f4273e466f79cf80df8cbaba034cca4f562687afbf |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENEY2OjM1NEI6RTFGMTNEOjEyN0ZCMEM6NkFGRkYxOTEiLCJ2aXNpdG9yX2lkIjoiMzc4MDQ0MjIzMzA1Mjg1MjYyNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 5d8229f1d1ba4e85e7499d69dc28715c51137754d47bf424826fa93db7258276 |
| hovercard-subject-tag | issue:1937702964 |
| 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/16247/issue_layout |
| twitter:image | https://opengraph.githubassets.com/001bdc21d2005b9d632bd67a23044b5fabbd88d538d395e41d44a8308c7a61c8/python/mypy/issues/16247 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/001bdc21d2005b9d632bd67a23044b5fabbd88d538d395e41d44a8308c7a61c8/python/mypy/issues/16247 |
| og:image:alt | Bug Report I have a decorator-like function that takes a Callable[Concatenate[...], ...] as an argument and returns a wrapped callable with the same signature. After upgrading from mypy 1.5.1 to 1.... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | intgr |
| 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