Title: Using `ParamSpec` in decorator with new type inference results in `Never` populated as type arguments · Issue #16512 · python/mypy · GitHub
Open Graph Title: Using `ParamSpec` in decorator with new type inference results in `Never` populated as type arguments · Issue #16512 · python/mypy
X Title: Using `ParamSpec` in decorator with new type inference results in `Never` populated as type arguments · Issue #16512 · python/mypy
Description: Bug Report Using a decorator including a ParamSpec variable on a function declaring multiple parameters from a generic protocol swaps any protocol argument to Never (pheuh, having a bit of trouble phrasing this decently..) To Reproduce I...
Open Graph Description: Bug Report Using a decorator including a ParamSpec variable on a function declaring multiple parameters from a generic protocol swaps any protocol argument to Never (pheuh, having a bit of trouble ...
X Description: Bug Report Using a decorator including a ParamSpec variable on a function declaring multiple parameters from a generic protocol swaps any protocol argument to Never (pheuh, having a bit of trouble ...
Opengraph URL: https://github.com/python/mypy/issues/16512
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Using `ParamSpec` in decorator with new type inference results in `Never` populated as type arguments","articleBody":"**Bug Report**\r\n\r\nUsing a decorator including a `ParamSpec` variable on a function declaring _multiple_ parameters from a generic protocol swaps any protocol argument to `Never` (pheuh, having a bit of trouble phrasing this decently..)\r\n\r\n**To Reproduce**\r\n\r\nI drilled down an issue in our code base, when running with `1.7.0`, to the following script. This passes fine with `1.6.1`. It might probably be reduced further.\r\n\r\nWhile I was at it I ran git bisect with the script below and ended up at 93d4cb0a2ef1723ce92f39ae61fe6a0c010eb90b (#16345) (CC @ilevkivskyi).\r\n\r\nI see that there's a flag to run with the old type inference to resolve things for now.\r\n\r\n[Playground link](https://mypy-play.net/?mypy=1.6.1&python=3.11&gist=22aedeb5da53bed31f42ad07110b7a3f)\r\n\r\n```python\r\nfrom collections.abc import Callable\r\nfrom typing import Concatenate, ParamSpec, Protocol, TypeVar\r\n\r\nT = TypeVar(\"T\")\r\nP = ParamSpec(\"P\")\r\nV_co = TypeVar(\"V_co\", covariant=True)\r\n\r\n\r\nclass Metric(Protocol[V_co]):\r\n def __call__(self) -> V_co:\r\n ...\r\n\r\n\r\ndef simple_metric(func: Callable[Concatenate[int, P], T]) -> Callable[P, T]:\r\n def inner(*args: P.args, **kwargs: P.kwargs) -> T:\r\n return func(*args, **kwargs)\r\n\r\n return inner\r\n\r\n\r\n@simple_metric\r\ndef Negate(count: int, /, metric: Metric[float]) -> float:\r\n return metric() * -1\r\n\r\n\r\n@simple_metric\r\ndef Combine(count: int, m1: Metric[T], m2: Metric[T], /, *more: Metric[T]) -> T:\r\n return m1()\r\n\r\n\r\nreveal_type(simple_metric)\r\nreveal_type(Negate)\r\nreveal_type(Combine)\r\n\r\ndef m1() -> float:\r\n return 0.0\r\n \r\ndef m2() -> float:\r\n return 1.0\r\n\r\nreveal_type(Combine(m1, m2))\r\n```\r\n\r\n**Expected Behavior**\r\n\r\nThere should be no `Never` populated as generic argument and script should pass.\r\n\r\n**Actual Behavior**\r\n\r\nSome strategic reveals in the script but the 2 errors it spits back are:\r\n\r\n```\r\nmain.py:41: error: Argument 1 to \"Combine\" has incompatible type \"Callable[[], float]\"; expected \"Metric[Never]\" [arg-type]\r\nmain.py:41: error: Argument 2 to \"Combine\" has incompatible type \"Callable[[], float]\"; expected \"Metric[Never]\" [arg-type]\r\nFound 2 errors in 1 file (checked 1 source file)\r\n```\r\n\r\nWhat's interesting is that if I only keep __1__ `Metric[T]` argument e.g.\r\n\r\n```python\r\n@simple_metric\r\ndef Combine(count: int, m1: Metric[T], /) -> T:\r\n return m1()\r\n```\r\n\r\nIt seems to get things right.\r\n\r\n**Your Environment**\r\n\r\n- Mypy version used: `1.7.0` (also `master`)\r\n- Mypy command-line flags: -\r\n- Mypy configuration options from `mypy.ini` (and other config files): -\r\n- Python version used: Python3.11\r\n","author":{"url":"https://github.com/flaeppe","@type":"Person","name":"flaeppe"},"datePublished":"2023-11-17T08:24:47Z","url":"https://github.com/python/mypy/issues/16512"}
| 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:56b3e80f-98f3-16e3-57e9-f09fbfe680b6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C256:B7CF9:3F8939:5558D0:6B002A5B |
| html-safe-nonce | 2e2e5e0ec3370d84097f5e2d8c7b915fd98c4dd88ac566bdf4a1731daa230a53 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMjU2OkI3Q0Y5OjNGODkzOTo1NTU4RDA6NkIwMDJBNUIiLCJ2aXNpdG9yX2lkIjoiMTQ4NjI2NDQ0OTUwNDM4OTcyMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 040c1df398dbbf9d66039b571b751378abda2885d59a6a94dc991391bf87f53a |
| hovercard-subject-tag | issue:1998533164 |
| 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/16512/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3b6276cb0d7360b118de299361dc941df2dc8d777497f9438b67853a188597e9/python/mypy/issues/16512 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3b6276cb0d7360b118de299361dc941df2dc8d777497f9438b67853a188597e9/python/mypy/issues/16512 |
| og:image:alt | Bug Report Using a decorator including a ParamSpec variable on a function declaring multiple parameters from a generic protocol swaps any protocol argument to Never (pheuh, having a bit of trouble ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | flaeppe |
| 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