Python 3.12+astterm
ast.TypeVarTuple
type parameters
Node for a *Ts type parameter in square brackets (Python 3.12): name is a string, plus default_value since 3.13.
Syntax
ast.TypeVarTuple(name, default_value=None)
As with ParamSpec, the star is not part of name: *Ts gives name='Ts', and only the node class distinguishes it from a TypeVar. There is no bound field. A use of *Ts inside annotations parses as Starred, not as TypeVarTuple, so the declaration and its use look different in the tree.
Examples
import ast
f = ast.parse('def f[*Ts](*args: *Ts): ...').body[0]
tp = f.type_params[0]
print(type(tp).__name__, tp.name) # → TypeVarTuple Ts
print(type(f.args.vararg.annotation).__name__) # → Starred
See also
Open in the full glossarydocs.python.orgReport an inaccuracy