TypeHinting tuples in Python

Yes, you can make the number of items in a tuple type hint flexible:

from typing import Tuple

def func(var: Tuple[int, ...]):
    pass

From the docs: https://docs.python.org/3/library/typing.html#typing.Tuple

To specify a variable-length tuple of homogeneous type, use literal ellipsis, e.g. Tuple[int, ...]. A plain Tuple is equivalent to Tuple[Any, ...], and in turn to tuple.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)