How do I use type annotations to indicate an unknown-length Tuple type parameter is the key of the returned Mapping?

Viewed 1254

Say I've got a function like this:

def a_function(data: Tuple[Tuple[str, ...], ...]) -> Mapping[Tuple[str, ...], int]:
    pass

Is there a way to indicate via type annotations that the Tuple[str, ...] is going to be the same Tuple[str, ...] that is passed in via the data parameter?

In other words, the tuple being passed in will contain a homogenous list of homogenous tuples that all might look like ('fred', 'smith'), ('ananya', 'cooper') and the returned dict will look like {('fred', 'smith'): 7, ('ananya', 'cooper'): 13}.

1 Answers
Related