Title: ParamSpec and protocols · Issue #13694 · python/mypy · GitHub
Open Graph Title: ParamSpec and protocols · Issue #13694 · python/mypy
X Title: ParamSpec and protocols · Issue #13694 · python/mypy
Description: Bug Report ParamSpec feature doesn't seem to work well when used with Protocol. To Reproduce from typing import Any, ParamSpec, Protocol P = ParamSpec("P") class Runnable(Protocol[P]): def run(self, *args: P.args, **kwargs: P.kwargs) -> ...
Open Graph Description: Bug Report ParamSpec feature doesn't seem to work well when used with Protocol. To Reproduce from typing import Any, ParamSpec, Protocol P = ParamSpec("P") class Runnable(Protocol[P]): def run(self...
X Description: Bug Report ParamSpec feature doesn't seem to work well when used with Protocol. To Reproduce from typing import Any, ParamSpec, Protocol P = ParamSpec("P") class Runnable(Protocol[P])...
Opengraph URL: https://github.com/python/mypy/issues/13694
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ParamSpec and protocols","articleBody":"**Bug Report**\r\n\r\nParamSpec feature doesn't seem to work well when used with Protocol.\r\n\r\n**To Reproduce**\r\n\r\n```python\r\nfrom typing import Any, ParamSpec, Protocol\r\n\r\nP = ParamSpec(\"P\")\r\n\r\n\r\nclass Runnable(Protocol[P]):\r\n def run(self, *args: P.args, **kwargs: P.kwargs) -> Any:\r\n ...\r\n\r\n\r\ndef foo(func: Runnable) -> int:\r\n ...\r\n\r\n\r\nclass A:\r\n def run(self, i: int) -> Any:\r\n ...\r\n\r\n\r\nfoo(A())\r\n```\r\n\r\n**Expected Behavior**\r\n\r\nIMO, mypy shouldn't report any bug, do you agree ?\r\n\r\n**Actual Behavior**\r\n\r\nmypy logs an error, which means mypy doesn't recognize A as implementing the `Runnable`protocol (which it does)\r\n\r\n```\r\ncommands/typing_debug.py:20: error: Argument 1 to \"foo\" has incompatible type \"A\"; expected \"Runnable[Any]\"\r\ncommands/typing_debug.py:20: note: Following member(s) of \"A\" have conflicts:\r\ncommands/typing_debug.py:20: note: Expected:\r\ncommands/typing_debug.py:20: note: def run(self, *args: Any, **kwargs: Any) -> Any\r\ncommands/typing_debug.py:20: note: Got:\r\ncommands/typing_debug.py:20: note: def run(self, i: int) -> Any\r\n```\r\n\r\nHowever if `foo` is defined as \r\n\r\n```\r\ndef foo(func: Runnable[int]) -> int:\r\n ...\r\n```\r\n\r\nmypy doesn't report any error.\r\n\r\n**Your Environment**\r\n\r\n\u003c!-- Include as many relevant details about the environment you experienced the bug in -->\r\n\r\n- Mypy version used: 0.971\r\n- Mypy command-line flags: no flag\r\n- Mypy configuration options from `mypy.ini` (and other config files): no config file\r\n- Python version used: 3.10.2\r\n- Operating system and version: MacOS 12.6\r\n","author":{"url":"https://github.com/mehdigmira","@type":"Person","name":"mehdigmira"},"datePublished":"2022-09-20T07:27:40Z","url":"https://github.com/python/mypy/issues/13694"}
| 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:41472cee-bb9b-1c3f-b467-3f986e345d46 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8614:302FC:B9F19:FB039:6B001C69 |
| html-safe-nonce | 50cbcd624114b01b84347d53600b7f828a585736cb950c88a370a62840d58e29 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NjE0OjMwMkZDOkI5RjE5OkZCMDM5OjZCMDAxQzY5IiwidmlzaXRvcl9pZCI6IjM5ODg0MDc1MjE2NDI1NTI0MjUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | f98278526d7877f8fa9db500ef3f76f76de41f7a611f35b5b75fea51656dbbd5 |
| hovercard-subject-tag | issue:1378947967 |
| 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/13694/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e11c0cd17d0c77eced7b15e48e6b63a3c6f5c7d40701ee816aa1ba614ffa2dd0/python/mypy/issues/13694 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e11c0cd17d0c77eced7b15e48e6b63a3c6f5c7d40701ee816aa1ba614ffa2dd0/python/mypy/issues/13694 |
| og:image:alt | Bug Report ParamSpec feature doesn't seem to work well when used with Protocol. To Reproduce from typing import Any, ParamSpec, Protocol P = ParamSpec("P") class Runnable(Protocol[P]): def run(self... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mehdigmira |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| 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 | 44c658b24abf00491fb7ae5f56d42c9f38cbeab2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width