I want to annotate a function that combines several iterators or generators into one, the case for two iterators is trivial:
def merge_two_iterators[T, H](gen1: Iterator[T], gen2: Iterator[H]) -> Iterator[tuple[T, H]]: ...
But I can’t make the arbitrary number of iterators work.
def merge_iterators[*Ts](*its: *Ts) -> Iterator[tuple[*Ts]]: ... # wrong
How can I unpack the list of iterators into a tuple? Unpack is not doing the trick.
The result should be something like this:
a: list[int] = [1, 2]
b: list[str] = ['a', 'b']
c = merge_iterators(a, b) # annotated as -> Iterator[tuple[int, str]] or list[tuple[int, str]]
2