Title: `ParamSpec` does not consider substitution of `@overload`s · Issue #13540 · python/mypy · GitHub
Open Graph Title: `ParamSpec` does not consider substitution of `@overload`s · Issue #13540 · python/mypy
X Title: `ParamSpec` does not consider substitution of `@overload`s · Issue #13540 · python/mypy
Description: Bug Report It looks like mypy only considers the first @overload of a function, when considering substitutions for a ParamSpec. In particular this affects use of asyncio.to_thread(f, arg), if f has @overloads. To Reproduce import asyncio...
Open Graph Description: Bug Report It looks like mypy only considers the first @overload of a function, when considering substitutions for a ParamSpec. In particular this affects use of asyncio.to_thread(f, arg), if f has...
X Description: Bug Report It looks like mypy only considers the first @overload of a function, when considering substitutions for a ParamSpec. In particular this affects use of asyncio.to_thread(f, arg), if f has...
Opengraph URL: https://github.com/python/mypy/issues/13540
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`ParamSpec` does not consider substitution of `@overload`s","articleBody":"**Bug Report**\r\n\r\nIt looks like `mypy` only considers the first `@overload` of a function, when considering substitutions for a `ParamSpec`.\r\n\r\nIn particular this affects use of `asyncio.to_thread(f, arg)`, if `f` has `@overload`s.\r\n\r\n**To Reproduce**\r\n\r\n```python\r\nimport asyncio\r\nfrom collections.abc import Callable\r\nfrom typing import overload\r\nfrom typing import TypeVar\r\n\r\nfrom typing_extensions import ParamSpec\r\n\r\n\r\n@overload\r\ndef f(x: int) -> None:\r\n ...\r\n\r\n\r\n@overload\r\ndef f(x: str) -> None:\r\n ...\r\n\r\n\r\ndef f(x) -> None:\r\n pass\r\n\r\n\r\n_P = ParamSpec(\"_P\")\r\n_R = TypeVar(\"_R\")\r\n\r\n\r\n# type signature modeled after asyncio.to_thread()\r\ndef generic(func: Callable[_P, _R], *args: _P.args, **kwargs: _P.kwargs) -> _R:\r\n ...\r\n\r\n\r\n# using first overload: passes\r\ngeneric(f, 1)\r\n# using second overload: fails\r\ngeneric(f, \"test\")\r\n```\r\n\r\n**Expected Behavior**\r\n\r\n```bash\r\n$ mypy t.py\r\nSuccess: no issues found in 1 source file\r\n```\r\n\r\n**Actual Behavior**\r\n\r\n```bash\r\n$ mypy t.py\r\nt.py:35: error: Argument 2 to \"generic\" has incompatible type \"str\"; expected \"int\"\r\nFound 1 error in 1 file (checked 1 source file)\r\n```\r\n\r\n**Your Environment**\r\n\r\n- Mypy version used: `mypy 0.971 (compiled: yes)`\r\n- Mypy command-line flags: `mypy t.py`\r\n- Mypy configuration options from `mypy.ini` (and other config files): none\r\n- Python version used: 3.10.4\r\n- Operating system and version: Ubuntu 22.04.1\r\n","author":{"url":"https://github.com/sbrudenell","@type":"Person","name":"sbrudenell"},"datePublished":"2022-08-28T07:25:11Z","url":"https://github.com/python/mypy/issues/13540"}
| 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:538ae57c-0a1b-0cfe-7fbe-cc106396cd36 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A052:34D7A7:33028E:451D76:6B00286D |
| html-safe-nonce | 7a010eb4f836d950be2ff21314a37809c7fbad828d77bea43ab1d97023dc86aa |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMDUyOjM0RDdBNzozMzAyOEU6NDUxRDc2OjZCMDAyODZEIiwidmlzaXRvcl9pZCI6IjQ1OTQ3NjE3MDE1OTI2NzIzNjUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 2cd89f3769fec79eaa52dd8b49f10c9329a61f76fd613d5e27f5b6b27e93683a |
| hovercard-subject-tag | issue:1353272123 |
| 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/13540/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f76014f45fa80acab80d96a17621e03a02aa4884f4c223ab794e67e72c8f7ed7/python/mypy/issues/13540 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f76014f45fa80acab80d96a17621e03a02aa4884f4c223ab794e67e72c8f7ed7/python/mypy/issues/13540 |
| og:image:alt | Bug Report It looks like mypy only considers the first @overload of a function, when considering substitutions for a ParamSpec. In particular this affects use of asyncio.to_thread(f, arg), if f has... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sbrudenell |
| 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 | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width