ID EN
Typing

Unpack

Python 3.11

Typing operator to conceptually mark an object as having been unpacked.

Syntax

PYTHON
typing.Unpack

Examples

Example 1
PYTHON
Ts = TypeVarTuple('Ts')
tup: tuple[*Ts]
 Effectively does:
tup: tuple[Unpack[Ts]]
Example 2
PYTHON
In older versions of Python, TypeVarTuple and Unpack
 are located in the `typing_extensions` backports package.
from typing_extensions import TypeVarTuple, Unpack

Ts = TypeVarTuple('Ts')
tup: tuple[*Ts]          Syntax error on Python <= 3.10!
tup: tuple[Unpack[Ts]]   Semantically equivalent, and backwards-compatible

See Also

type variable tuple typing.TypeVarTuple builtins.tuple