Parameterize a generic with typing.TypeVarTuple
Answer: TypeVarTuple is a type variable tuple: a specialized form of type variable that enables variadic generics. PEP 646 introduces it so a generic can be parameterised with an arbitrary number of types, not just a single TypeVar.
Variadic generics
PEP 484 introduced TypeVar, enabling creation of generics parameterised with a single type. TypeVarTuple enables variadic generics. In particular, it allows array-like structures in numerical computing libraries to be parameterised with the array shape.
Declaring and unpacking
Type variable tuples can be declared in a type parameter list or with TypeVarTuple("name"). They must always be unpacked. The typing page and the PEP both describe Unpack for backwards compatibility with earlier syntax. A TypeVarTuple is not a single TypeVar.
| TypeVar | TypeVarTuple | |---|---| | TypeVar | Parameterises a generic with a single type | | TypeVarTuple | Parameterises with an arbitrary number of types | | Unpack | Backwards-compatible unpacking syntax | | array shape | Motivating case in numerical libraries |
See also
Claims
- id: C1 claim: TypeVarTuple parameterizes a generic with an arbitrary number of types. source: S1 evidence: "enabling parameterisation with an arbitrary number of types"
- id: C2 claim: That variadic type variable enables variadic generics, including array shapes. source: S1 evidence: "a variadic type variable, enabling variadic generics"
- id: C3 claim: In typing, TypeVarTuple is a type variable tuple for variadic generics. source: S2 evidence: "A specialized form of type variable that enables variadic generics"
Sources
- [S1] PEP 646 – Variadic Generics. Python PEPs. https://peps.python.org/pep-0646/ . License: Public-Domain. Accessed 2026-11-19.
- [S2] typing — Support for type hints. Python docs. https://docs.python.org/3/library/typing.html . License: PSF-2.0. Accessed 2026-11-19.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python PEPs, PEP 646 – Variadic Generics; Python docs, typing — Support for type hints. Public-Domain; PSF-2.0. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python PEPs, PEP 646 – Variadic Generics; Python docs, typing — Support for type hints. Public-Domain; PSF-2.0.
Cite this
iinventedlight. 2026. "Parameterize a generic with typing.TypeVarTuple." iinventedlight Library, iil:note:mwpbd00p, version of 2026-11-19. https://iinventedlight.com/library/notes/python-typing-typevar-tuple/. License: CC-BY-4.0.
@misc{iil_note_mwpbd00p,
author = {{iinventedlight}},
title = {{Parameterize a generic with typing.TypeVarTuple}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-19},
url = {https://iinventedlight.com/library/notes/python-typing-typevar-tuple/},
note = {Permanent ID iil:note:mwpbd00p. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- python-typing-typevar-tuple.table.json (table; CC-BY-4.0)
- python-typing-typevar-tuple.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-typing-typevar-tuple.md.