Type hints for *args in Python: Annotate the element type

Type hints for *args in Python: Annotate the element type

How to annotate *args in Python? Just set the elements’ type; we know it’s a tuple:

def mysum(*args:int) -> int:
    total = 0
    for n in args:
        total += n
    return total

Normally, tuples contain different types. In args, we assume all values have the same type.