PEP 827: Type Manipulation

A colleague created a function similar to bufferCount in rx js (RxJS) and this got me wondering how to better type this. I got this, but it feels weird. Is there something better I’m missing? I couldn’t really see how to make a tuple of T of size based on a parameter.

@overload
def batch[TT](
    batch_size: Length[TT],
) -> Operator[GetArg[TT, tuple, Literal[0]], TT]:
    ...

@overload
def batch[T](
    batch_size: int,
) -> Operator[T, tuple[T, ...]]:
    ...

def batch[T](
    batch_size: int,
) -> Operator[T, tuple[T, ...]]:
    ...