How to annotate function that takes a tuple of variable length? (variadic tuple type annotation)
Variable length homogeneous tuple we can annotate using ...
literal (aka Ellipsis
) like
def process_tuple(t: Tuple[str, ...]):
...
after that errors should go away.
From docs
To specify a variable-length tuple of homogeneous type, use literal ellipsis, e.g.
Tuple[int, ...]
. A plainTuple
is equivalent toTuple[Any, ...]
, and in turn totuple
.