Title: ParamSpec: Allow only `P.args` · Issue #1000 · python/typing · GitHub
Open Graph Title: ParamSpec: Allow only `P.args` · Issue #1000 · python/typing
X Title: ParamSpec: Allow only `P.args` · Issue #1000 · python/typing
Description: I would like to use ParamSpec to type a function that accepts a Callable[P, Any] and *args which will be passed to the callable. The function itself does not accept keyword arguments. As an example, AbstractEventLoop.call_soon behaves si...
Open Graph Description: I would like to use ParamSpec to type a function that accepts a Callable[P, Any] and *args which will be passed to the callable. The function itself does not accept keyword arguments. As an example...
X Description: I would like to use ParamSpec to type a function that accepts a Callable[P, Any] and *args which will be passed to the callable. The function itself does not accept keyword arguments. As an example...
Opengraph URL: https://github.com/python/typing/issues/1000
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ParamSpec: Allow only `P.args`","articleBody":"I would like to use `ParamSpec` to type a function that accepts a `Callable[P, Any]` and `*args` which will be passed to the callable. The function itself does not accept keyword arguments. As an example, `AbstractEventLoop.call_soon` behaves similar. This is the current Typeshed definition\r\n```py\r\n def call_soon(self, callback: Callable[..., Any], *args: Any) -> Handle: ...\r\n```\r\n[typeshed -> stdlib/asyncio/events.pyi -> AbstractEventLoop](https://github.com/python/typeshed/blob/03861b5a1d317b14f516771f296e0325a13ed314/stdlib/asyncio/events.pyi#L90-L95)\r\n\r\n```py\r\nP = ParamSpec(\"P\")\r\n\r\n def call_soon(self, callback: Callable[P, Any], *args: P.args) -> Handle: ...\r\n```\r\nIntuitively adding a ParamSpec variable like this would make sense: \"Only except `*args`. If any arguments are passed, they need to match those of the `callback`.\" I would also expect that if `callback` has required arguments, they need to be passed with `*args` to `call_soon`.\r\n\r\nThe issue here is that PEP 612 explicitly forbids specifying `P.args` or `P.kwargs` alone. They always need to be together.\r\nhttps://www.python.org/dev/peps/pep-0612/#id2\r\n\r\n```\r\nFurthermore, because the default kind of parameter in Python ((x: int)) may be addressed\r\nboth positionally and through its name, two valid invocations of a (*args: P.args, **kwargs: P.kwargs)\r\nfunction may give different partitions of the same set of parameters. Therefore, we need to make\r\nsure that these special types are only brought into the world together, and are used together,\r\nso that our usage is valid for all possible partitions.\r\n```\r\n\r\nI do wonder if this strict limitation makes sense or if there are other ways to work around it so the case described above could be supported. After all it's similar to adding `**kwargs` to the function signature without ever passing keyword arguments.\r\n```py\r\n def call_soon(self, callback: Callable[P, Any], *args: P.args, **kwargs: P.kwargs) -> Handle: ...\r\n```","author":{"url":"https://github.com/cdce8p","@type":"Person","name":"cdce8p"},"datePublished":"2022-01-02T15:43:17Z","url":"https://github.com/python/typing/issues/1000"}
| 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:8b2ae65c-3871-4861-bfaf-f6d3040e88f9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D962:30CC09:1C65B8D:261C1A2:6B00016C |
| html-safe-nonce | c624441f14580fdebd2426fec147c0c3c335e6ae07531c772626fc5f200afb27 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEOTYyOjMwQ0MwOToxQzY1QjhEOjI2MUMxQTI6NkIwMDAxNkMiLCJ2aXNpdG9yX2lkIjoiNjExOTA4MjIwMDk0OTMyNjE4OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d94ac05a53427ef5004b8b0eea1f437688f48f48e144914089ddb15bdb6c9a67 |
| hovercard-subject-tag | issue:1092045330 |
| 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/typing/1000/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5e1f335f55b71f330c27d7dd1e8ba1ff9e632aed3ceae3c02eb7d2c09bd8d116/python/typing/issues/1000 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5e1f335f55b71f330c27d7dd1e8ba1ff9e632aed3ceae3c02eb7d2c09bd8d116/python/typing/issues/1000 |
| og:image:alt | I would like to use ParamSpec to type a function that accepts a Callable[P, Any] and *args which will be passed to the callable. The function itself does not accept keyword arguments. As an example... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | cdce8p |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0a0d8686a27478df474dd7415776a7a080cde8838b3cd92ea7601187572e5729 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typing git https://github.com/python/typing.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 24604008 |
| octolytics-dimension-repository_nwo | python/typing |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24604008 |
| octolytics-dimension-repository_network_root_nwo | python/typing |
| 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