Title: Union of ParamSpec? · Issue #17481 · python/mypy · GitHub
Open Graph Title: Union of ParamSpec? · Issue #17481 · python/mypy
X Title: Union of ParamSpec? · Issue #17481 · python/mypy
Description: Feature Currently it's possible to concatenate a type to a paramspec to get a new paramspec. I think I may need the ability to concatenate two paramspecs, like: P = ParamSpec('P') Q = ParamSpec('Q') R = TypeVar("R") Callable[Concatenate[...
Open Graph Description: Feature Currently it's possible to concatenate a type to a paramspec to get a new paramspec. I think I may need the ability to concatenate two paramspecs, like: P = ParamSpec('P') Q = ParamSpec('Q'...
X Description: Feature Currently it's possible to concatenate a type to a paramspec to get a new paramspec. I think I may need the ability to concatenate two paramspecs, like: P = ParamSpec('P') Q = P...
Opengraph URL: https://github.com/python/mypy/issues/17481
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Union of ParamSpec?","articleBody":"**Feature**\r\n\r\nCurrently it's possible to concatenate a type to a paramspec to get a new paramspec.\r\n\r\nI think I may need the ability to concatenate two paramspecs, like:\r\n\r\n P = ParamSpec('P')\r\n Q = ParamSpec('Q')\r\n R = TypeVar(\"R\")\r\n Callable[Concatenate[P, Q], R]\r\n\r\n**Pitch**\r\n\r\nI'm trying to describe partial-like functions, I spotted https://github.com/python/mypy/pull/16939 which solves if for `functools.partial` (which is good) but still not giving a way to describe other partial-like functions.\r\n\r\nCurrently I can successfully describe the \"removal\" of one or multiple parameters:\r\n\r\n```python\r\nfrom collections.abc import Callable\r\nfrom typing import Concatenate, Generic, ParamSpec, TypeVar\r\n\r\nP = ParamSpec('P')\r\nQ = ParamSpec('Q')\r\nS = TypeVar('S')\r\nT = TypeVar('T')\r\nU = TypeVar('U')\r\n\r\n\r\ndef substract_one_parameter(given: T, func: Callable[Concatenate[T, P], U]) -> Callable[P, U]:\r\n def inner(*args: P.args, **kwargs: P.kwargs) -> U:\r\n return func(given, *args, **kwargs)\r\n return inner\r\n\r\n\r\ndef substract_two_parameters(first: S, second: T, func: Callable[Concatenate[S, T, P], U]) -> Callable[P, U]:\r\n def inner(*args: P.args, **kwargs: P.kwargs) -> U:\r\n return func(first, second, *args, **kwargs)\r\n return inner\r\n\r\n\r\ndef int_int_int(a: int, b: int) -> int:\r\n return a + b\r\n\r\n\r\nc = substract_one_parameter(1, int_int_int)\r\nreveal_type(c) # def (b: builtins.int) -> builtins.int\r\nprint(c(2))\r\n\r\n\r\nd = substract_two_parameters(1, 2, int_int_int)\r\nreveal_type(d) # def () -> builtins.int\r\nprint(d())\r\n```\r\n\r\nBut what I think I need is:\r\n\r\n```python\r\n# P are the \"removed\" parameters\r\n# Q are the \"kept\" parameters\r\ndef substract_n_parameters(func: Callable[Concatenate[P, Q], U], *outer_args: P.args, **outer_kwargs: P.kwargs) -> Callable[Q, U]:\r\n def inner(*args: Q.args, **kwargs: Q.kwargs) -> U:\r\n return func(*outer_args, *args, **outer_kwargs, **kwargs)\r\n return inner\r\n```\r\n\r\nI feel that would cleanly express the \"removal\" of `P` from `[P, Q]`, without the need to introduce a new function like `Difference[P, Q]`.\r\n\r\nI feel like this could also be used for the real `functools.partial`, maybe simplifying the current (working, yeah) implementation.\r\n","author":{"url":"https://github.com/JulienPalard","@type":"Person","name":"JulienPalard"},"datePublished":"2024-07-04T11:49:20Z","url":"https://github.com/python/mypy/issues/17481"}
| 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:cb410cdf-da68-3274-dc0d-9c1c5921effe |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8C4A:1EFC1C:1093F59:15B4F3E:6AFFFB77 |
| html-safe-nonce | a1600275d8d3a0e2584ad9871c8346d9ab503cf4cc1db9e99c05c49904cf6d0f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QzRBOjFFRkMxQzoxMDkzRjU5OjE1QjRGM0U6NkFGRkZCNzciLCJ2aXNpdG9yX2lkIjoiNjM3NzcyNzQ4MDg2MTU1NTU3NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | b64071b542b1699247c6dc3d585354f13e5bca78bb465999e2089a5b850fec61 |
| hovercard-subject-tag | issue:2390682323 |
| 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/17481/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5534fa64f390d6dd52b0b5653f31b19ba534ae92a179ba114a19414cf9053d8b/python/mypy/issues/17481 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5534fa64f390d6dd52b0b5653f31b19ba534ae92a179ba114a19414cf9053d8b/python/mypy/issues/17481 |
| og:image:alt | Feature Currently it's possible to concatenate a type to a paramspec to get a new paramspec. I think I may need the ability to concatenate two paramspecs, like: P = ParamSpec('P') Q = ParamSpec('Q'... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JulienPalard |
| 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