← All notes

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

Sources

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

Permanent ID: iil:note:mwpbd00p

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.},
}

Markdown

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.

All artifact files (JSON index)

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.