Title: Clarify the valid use locations of `typing.Concatenate` · Issue #2140 · python/typing · GitHub
Open Graph Title: Clarify the valid use locations of `typing.Concatenate` · Issue #2140 · python/typing
X Title: Clarify the valid use locations of `typing.Concatenate` · Issue #2140 · python/typing
Description: In python/cpython#142965, it was reported that the documentation of typing.Concatenate is "incorrect" (documentation that originates back to python/cpython#24000). @A5rocks, in your example, Concatenate[int, P_2] somewhat finally lands a...
Open Graph Description: In python/cpython#142965, it was reported that the documentation of typing.Concatenate is "incorrect" (documentation that originates back to python/cpython#24000). @A5rocks, in your example, Concat...
X Description: In python/cpython#142965, it was reported that the documentation of typing.Concatenate is "incorrect" (documentation that originates back to python/cpython#24000). @A5rocks, in your examp...
Opengraph URL: https://github.com/python/typing/issues/2140
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Clarify the valid use locations of `typing.Concatenate`","articleBody":"\u003c!-- Please describe the problem or your idea or suggestion below. Please include the URL of the page this issue is about, if applicable. --\u003e\n\nIn python/cpython#142965, it was reported that the documentation of `typing.Concatenate` is \"incorrect\" (documentation that originates back to python/cpython#24000).\n\n@A5rocks, in your example, `Concatenate[int, P_2]` somewhat finally lands as a first argument to `Callable`, just indirectly.\nThis snippet previously defined:\n\n```py\nP_2 = ParamSpec(\"P_2\")\n\nclass X(Generic[T, P]):\n f: Callable[P, int]\n x: T\n```\n\nSimilar example is included in the typing spec:\n\nhttps://typing.python.org/en/latest/spec/generics.html#user-defined-generic-classes\n\n```py\nclass X[T, **P]:\n f: Callable[P, int]\n x: T\n\n# (...)\ndef accept_concatenate[**P](x: X[int, Concatenate[int, P]]) -\u003e str: ... # Accepted\n```\n\nHowever, it seems that the current situation (confirmed with mypy, pyright and ty) is that you can use `Concatenate` in all valid locations of `ParamSpec` except directly in a `Concatenate`. I.e., you can't do `Concatenate[int, Concatenate[str, P]]`), but you can (besides passing `Concatenate` form as the first argument to `Callable`):\n\n1) Accumulate `Concatenate`s as `ParamSpec`s\n\n```py\nfrom collections.abc import Callable\nfrom typing import Concatenate\n\ntype Y[**P] = Callable[Concatenate[int, P], None]\ntype X[**P] = Y[Concatenate[int, P]]\n\ndef foo(f: X[str]) -\u003e None:\n reveal_type(f)\n # mypy: def (builtins.int, builtins.int, builtins.str)\n # pyright: (int, int, str) -\u003e None\n # ty: (...) -\u003e None\n```\n\n2) Bind `Concatenate`s to user-defined generics as `ParamSpec`s\n\n```py\nclass X[T, **P]:\n f: Callable[P, int]\n x: T\n\ndef accept_concatenate[**P](x: X[int, Concatenate[int, P]]) -\u003e str: ...\n```\n\n3) Use `Concatenate` as a type argument to `tuple` -- is this correct?\n\n```py\nfrom typing import Concatenate\n\ndef c(t: tuple[Concatenate[int, ...]]) -\u003e None:\n reveal_type(c)\n # mypy: def (t: tuple[[builtins.int, *Any, **Any]])\n # pyright: (t: tuple[Concatenate[int, ...]]) -\u003e None\n # ty: def c(t: tuple[@Todo]) -\u003e None\n```\n\nI've found this mostly by poking around -- I haven't analyzed the actual implementations (yet).\nI'll continue to investigate this from [these searches](https://github.com/johnslavik/python-type-checkers/blob/8aa628e36a8074be853284019eb3f7365f243f3b/searches/concatenate.md).\n\nI think that the valid use locations of `Concatenate` should be clarified in the typing spec and then in the CPython docs.\n\nIs there anything else I overlooked? CC @JelleZijlstra @AlexWaygood \n","author":{"url":"https://github.com/johnslavik","@type":"Person","name":"johnslavik"},"datePublished":"2025-12-20T16:47:17.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/2140/typing/issues/2140"}
| 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:631f9eb8-13ac-d452-6053-da5d0f67bc5a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D93A:29DE21:B78FB7:FE0F27:696F4541 |
| html-safe-nonce | 3705838fd59c765bd09b12fe6b7ed65e1d8ca26a20c0758e30780006e80f31da |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEOTNBOjI5REUyMTpCNzhGQjc6RkUwRjI3OjY5NkY0NTQxIiwidmlzaXRvcl9pZCI6IjE2MTEzMjA3Njc0MjI2MTI4MDEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | f9deb1042a28daccc96c09de8d428b8aed0f65a4517afb77c24c1e3e3157154b |
| hovercard-subject-tag | issue:3750214931 |
| 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/2140/issue_layout |
| twitter:image | https://opengraph.githubassets.com/28eea8dc55e47d26a5357680ffcea43cb6d93c6e5aa174e529d1b27aaf827bb7/python/typing/issues/2140 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/28eea8dc55e47d26a5357680ffcea43cb6d93c6e5aa174e529d1b27aaf827bb7/python/typing/issues/2140 |
| og:image:alt | In python/cpython#142965, it was reported that the documentation of typing.Concatenate is "incorrect" (documentation that originates back to python/cpython#24000). @A5rocks, in your example, Concat... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | johnslavik |
| hostname | github.com |
| expected-hostname | github.com |
| None | b278ad162d35332b6de714dfb005de04386c4d92df6475522bef910f491a35ee |
| 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 | 39aed5006635ab6f45e6b77d23e73b08a00272a3 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width