Title: Proposal: Support Unpacked `TypeVarTuple` and `tuple` in `Concatenate` · Issue #2332 · python/typing · GitHub
Open Graph Title: Proposal: Support Unpacked `TypeVarTuple` and `tuple` in `Concatenate` · Issue #2332 · python/typing
X Title: Proposal: Support Unpacked `TypeVarTuple` and `tuple` in `Concatenate` · Issue #2332 · python/typing
Description: Abstract PEP 612 introduced ParamSpec and Concatenate to prepend fixed positional parameters to a callable's signature. PEP 646 introduced TypeVarTuple for variadic positional typing in Callable[[*Ts], R]. Because the two PEPs were devel...
Open Graph Description: Abstract PEP 612 introduced ParamSpec and Concatenate to prepend fixed positional parameters to a callable's signature. PEP 646 introduced TypeVarTuple for variadic positional typing in Callable[[*...
X Description: Abstract PEP 612 introduced ParamSpec and Concatenate to prepend fixed positional parameters to a callable's signature. PEP 646 introduced TypeVarTuple for variadic positional typing in Callabl...
Opengraph URL: https://github.com/python/typing/issues/2332
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Proposal: Support Unpacked `TypeVarTuple` and `tuple` in `Concatenate`","articleBody":"## Abstract\n\n[PEP 612](https://peps.python.org/pep-0612/) introduced `ParamSpec` and `Concatenate` to prepend fixed positional parameters to a callable's signature. [PEP 646](https://peps.python.org/pep-0646/) introduced `TypeVarTuple` for variadic positional typing in `Callable[[*Ts], R]`. Because the two PEPs were developed independently, the [typing specification](https://typing.python.org/en/latest/spec/generics.html#valid-use-locations) does not allow unpacked types (`*Ts` or `*tuple[...]`) inside `Concatenate`.\n\nThis proposal extends `Concatenate` to accept `unpack_expression`s in its prefix, enabling `Callable[Concatenate[*Ts, P], R]`.\n\n---\n\n## Motivation\n\nHigher-order abstractions like partial application helpers and execution wrappers need to capture an arbitrary number of leading positional arguments while preserving the remaining signature (keyword-only params, defaults, `**kwargs`) via `ParamSpec`. Today, this requires repetitive overload ladders:\n\n```python\nfrom typing import Any, Callable, Concatenate, overload\n\nclass Wrapper[**P, R]:\n @overload\n def __init__(self, fn: Callable[P, R]) -> None: ...\n\n @overload\n def __init__[G1](\n self,\n fn: Callable[Concatenate[G1, P], R],\n __g1: G1,\n /,\n ) -> None: ...\n\n @overload\n def __init__[G1, G2](\n self,\n fn: Callable[Concatenate[G1, G2, P], R],\n __g1: G1,\n __g2: G2,\n /,\n ) -> None: ...\n\n # Must repeat up to arbitrary maximum arity...\n def __init__(self, fn: Callable[..., R], *args: Any) -> None:\n self._fn = fn\n self._args = args\n\n def __call__(self, *args: P.args, **kwargs: P.kwargs) -> R:\n return self._fn(*self._args, *args, **kwargs)\n```\n\nWith this proposal, the entire ladder collapses to a single generic signature:\n\n```python\nfrom __future__ import annotations\nfrom typing import Callable, Concatenate\n\nclass Wrapper[**P, R, *Ts]:\n def __init__(self, fn: Callable[Concatenate[*Ts, P], R], *args: *Ts) -> None:\n self._fn = fn\n self._args = args\n\n def __call__(self, *args: P.args, **kwargs: P.kwargs) -> R:\n return self._fn(*self._args, *args, **kwargs)\n\ndef f(a: str, b: int, *, flag: bool = False, x: float) -> bool: ...\n\n# Ts = () -> P = (a: str, b: int, *, flag: bool = ..., x: float)\nw0 = Wrapper(f)\nr0 = w0(\"hello\", 42, x=3.14, flag=True) # type: bool\n\n# Ts = (str,) -> P = (b: int, *, flag: bool = ..., x: float)\nw1 = Wrapper(f, \"hello\")\nr1 = w1(42, x=3.14) # type: bool\n\n# Ts = (str, int) -> P = (*, flag: bool = ..., x: float)\nw2 = Wrapper(f, \"hello\", 42)\nr2 = w2(x=3.14) # type: bool\n```\n\n---\n\n## Specification\n\n### Grammar\n\nUpdate the `Concatenate` grammar in the [typing specification](https://typing.python.org/en/latest/spec/generics.html#valid-use-locations) from:\n\n```\nconcatenate ::= \"Concatenate\" \"[\" type_expression (\",\" type_expression)* \",\" parameter_specification_variable \"]\"\n```\n\nto:\n\n```\nconcatenate_prefix_item ::= type_expression | unpack_expression\nconcatenate ::= \"Concatenate\" \"[\" concatenate_prefix_item (\",\" concatenate_prefix_item)* \",\" parameter_specification_variable \"]\"\n```\n\n### Semantics\n\nExpansion follows existing PEP 646 semantics: when `*Ts` is bound to `tuple[T1, T2, ..., Tn]`, `Concatenate[*Ts, P]` is equivalent to `Concatenate[T1, T2, ..., Tn, P]`. When `*Ts` is bound to `tuple[()]`, `Concatenate[*Ts, P]` simplifies to `P`. Individual type expressions and unpack expressions may be freely combined in the prefix (e.g. `Concatenate[LeadingArg, *Ts, P]`).\n\n---\n\n## Open Question: Splitting Boundary\n\nThe core design question is: **how does a type checker determine the split between the prefix and `ParamSpec P`?**\n\nWhen the prefix length is statically known, splitting is unambiguous. This covers concrete bounded tuples (`Concatenate[*tuple[int, str], P]` — always length 2) and value-anchored `TypeVarTuple`s where a companion `*args: *Ts` pins the length at the call site (the `Wrapper` example above). These are the primary use cases.\n\nAmbiguity arises when the prefix length is *not* statically determined:\n\n**Case A — Unanchored `*Ts`** (no companion `*args: *Ts`):\n```python\nclass TaskRunner[**P, R, *Ts]:\n def __init__(self, fn: Callable[Concatenate[*Ts, P], R]) -> None: ...\n\ndef compute(user_id: int, query: str, *, timeout: float = 5.0) -> bool: ...\n\n# How many positional params should *Ts capture vs. leave in P?\ntask = TaskRunner(compute)\n```\n\n**Case B — Unbounded tuple (`*tuple[T, ...]`)**:\n```python\ndef strip_leading_ints[**P, R](\n fn: Callable[Concatenate[*tuple[int, ...], P], R]\n) -> Callable[P, R]: ...\n\ndef example(x: int, y: int, z: int, *, flag: bool = False) -> None: ...\n\n# *tuple[int, ...] could match 0, 1, 2, or 3 leading int parameters.\nwrapped = strip_leading_ints(example)\n```\n\n**Options:**\n\n- **Option 1 — Greedy prefix:** The prefix consumes all matching positional-capable parameters. In Case A, `*Ts = (int, str)` and `P = (*, timeout: float = 5.0)`. In Case B, all 3 ints are consumed, leaving `P = (*, flag: bool = False)`.\n\n- **Option 2 — Restrict to fixed-length prefixes initially:** Require the prefix length to be statically determined (concrete bounded tuples, companion `*args: *Ts`, or explicit specialization). Reject unanchored/unbounded prefixes as ambiguous and defer them to a future extension.\n","author":{"url":"https://github.com/ringohoffman","@type":"Person","name":"ringohoffman"},"datePublished":"2026-08-05T23:41:11Z","url":"https://github.com/python/typing/issues/2332"}
| 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:f07a240b-a0f1-bc2f-f01c-e173cd6ad112 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BC8C:14BBAC:207A9A:29EF1E:6AFF856B |
| html-safe-nonce | 05f25ae004d1b522a835fc20b29f2cb41e9fe22cb54d455f67ddb32920f6d396 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQzhDOjE0QkJBQzoyMDdBOUE6MjlFRjFFOjZBRkY4NTZCIiwidmlzaXRvcl9pZCI6IjM5MTczOTk1MzYwMDczNDk2MTEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 68dcbd467cd603c55a74ffcb4169466684069365a48fc862927c94fa45f2f55d |
| hovercard-subject-tag | issue:5076155860 |
| 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/2332/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c3707f48a0fba30f0f620cd3c8deb074940195d4a362bce7d6f1c7d42f8c0ade/python/typing/issues/2332 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c3707f48a0fba30f0f620cd3c8deb074940195d4a362bce7d6f1c7d42f8c0ade/python/typing/issues/2332 |
| og:image:alt | Abstract PEP 612 introduced ParamSpec and Concatenate to prepend fixed positional parameters to a callable's signature. PEP 646 introduced TypeVarTuple for variadic positional typing in Callable[[*... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ringohoffman |
| hostname | github.com |
| expected-hostname | github.com |
| None | 19488db4031f00b04ea79b4c70b5dd32cfa873a8d20b3877f3896b8e2d195946 |
| 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 | 7952f5285f4ba685d70c4c7540ad3cc9dc9746b8 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width