Type hints for starred arguments

Viewed 432

Suppose we want to add type hinting to a function that adds a bunch of integers together using a starred argument:

def add_integers(*integers):
   return sum(integers)

Is the correct practice to give the integer type, since that's what each individual argument will be?

def add_integers(*integers: int):
   return sum(integers)

...or to give the type of the resulting variable, which ends up being a sequence (tuple) of integers?

def add_integers(*integers: Sequence[int]):
   return sum(integers)
1 Answers

According to PEP 484, the correct hinting is the first one

Related